devxlogo

IMG tag and relative/evaluated location

IMG tag and relative/evaluated location

Question:
We have a structure already defined that is now being modified, containing more than 400 pages that include IMG tags. The entire “mess” is being moved to another server/structure such that the relative references in the IMG tags will no longer be valid.

Is there any way other than (a) editing 400+ individual HTML docs, or (b) writing a script to perform the changes, that allows for the “../../” relative references in the IMG tags to be evaluated with some type of variable a la UNIX scripts? Or is this beyond the scope of basic HTML?

For example, IMG SRC=”../../abc/mygif.gif” &#151 is there any way to have “../../abc/” replaced with a variable entity/expression that can be evaluated in its place, as in:IMG SRC=some_token “mygif.gif”?

Answer:
You will need to either run a script or use a local editor, such asHomeSite, to edit the path names. A simple search and replace script wouldbe something like this:

#! /bin/csh# Call this file snr.sh# Replace FILE with * for all files, or a partial file name# Replace OLDPATH with the old path name and NEWPATH with# the new path name.# Don't forget to backslash any slashes, so if the OLDPATH is# ../../ you will need to type ../../foreach f (FILE)foreach g ($f/*.html)	cat $g | sed -e 's/OLDPATH/NEWPATH/g' > tmp	mv -f tmp $gendend

Place it in the root directory, and make it executable by typing:

%  chmod +x snr.sh

and run it by typing:

%  snr.sh

See also  5 Tips for Working With an Onsite Interpreter
devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist