Page 1  2
A viewer named Nathan sent this email to "The Screen Savers":
"After spending months coding links to images and features on my website, I have to switch to a new server. Is there a program that lets me type in specific text and change it all to a new address?"

Nathan asks a question that many a webmaster has asked before him: How can you quickly change a piece of text in all the HTML files on your site? Fortunately, it's very easy to do using Perl. (You could also cobble something together in shell script, but it's easier in Perl.)

Let's say you want to change the name of the directory you use to store image files from "images" to "pix." A global search and replace across all the HTML files in the directory would do the trick. Enter this at the command line and you're done:

perl -i 'bak' -pe 's/images/pix/g' *.html

This Perl command will process all the .html files in the current directory, replacing the word "images" with the word "pix." The command preserves the original files by adding .orig to the original file names.

Find out how the Perl command works.




Page 1  2