need to open a series of files and "find + replace" the same thing in all..

Don
Joined
21 Oct 2002
Posts
46,778
Location
Parts Unknown
ok, basically i've got this now..
http://bleddyn.co.uk/photos/france/pages/DSC01060_jpg.htm

and want them all to look like this..

http://bleddyn.co.uk/photos/france/pages/DSC00952_jpg.htm



so basically i need to

open a series of .htm files
1 remove <h2>*.</h2>
2 replace 'Previous' with <img src="previous.png" alt="previous" width="20" height="20" border="0">
3 replace 'Home' with <img src="home.png" alt="home" width="20" height="20" border="0">
4 replace 'Next' with <img src="next.png" alt="next" width="20" height="20" border="0">
save (same filename)


can someone help me with this? i'm used to using batch files, but only on the filenames etc themselves, never the content..
 
Got a linux box handy?

Stick all the files in a folder, put the below in an executable file in the same folder and run it.
Code:
#!/bin/bash
for i in `ls *.htm`
do
sed -in 's/<h2>.*<\/h2>//g' $i
sed -in 's/Home/<img src="previous.png" alt="previous" width="20" height="20" border="0">/g' $i
sed -in 's/Previous/<img src="home.png" alt="home" width="20" height="20" border="0">/g' $i
sed -in 's/Next/<img src="next.png" alt="next" width="20" height="20" border="0">/g' $i
echo "$i search and replace complete."
done
 
sweet, that would do just the file in the subfolder that its contained in yeah?

-would prefer to do it on a pc, so i can keep the whole site on my usbkey, so if anyone can convert that to .bat, i'd really appreciate it
 
Last edited:
My batch file knowledge is pretty rusty, but get sed for windows: http://www.cornerstonemag.com/sed/

and try something like:
Code:
for %%i in (*.htm) do sed -in 's/<h2>.*<\/h2>//g' %%i
for %%i in (*.htm) do sed -in 's/Home/<img src="previous.png" alt="previous" width="20" height="20" border="0">/g' %%i
for %%i in (*.htm) do sed -in 's/Previous/<img src="home.png" alt="home" width="20" height="20" border="0">/g' %%i
for %%i in (*.htm) do sed -in 's/Next/<img src="next.png" alt="next" width="20" height="20" border="0">/g' %%i

The exact formatting of the sed command is probably different, but the -i switch (make changes in the original file) is key.
 
I recommend using a scripting language like PHP rather than having a separate HTML page for each image. You could load up all the files in the directory into an array and generate the Previous and Next buttons from that.
 
Back
Top Bottom