Perl global search and replace

I produce a monthly web magazine which consists of eight years worth of flat HTML files. One of the writers, who recently got a new email address, asked me to update it everywhere it appeared on the site - which was in dozens of .htm and .html files nested in subdirectories all over the tree. The very thought gave me a headache.

But, after a little researching, I found this quick Perl script did the trick on files piped from the find command:

[trapani@colossus html]$ find . -name “*.htm*” | xargs perl -pi -e ’s/user\@oldaddress.com/user\@newaddress.com/g’

Scary, running that sucker a bit recklessly on the production server, but it totally worked, and fast. Modified from the suggestion at this O’Reilly Linux Server Hack.

Comments are closed.