« How Often Does Your OS Crash? | Main | Welcome Paul »

August 12, 2003

Tuesday's Perl Hack (replacing text in many files)

At work we are in the process of changing our name from HSDB (Health Sciences Database) to TUSK (Tufts University Sciences Knowledgebase). The first wave is to change the logo and all the text references in the static portions of our site. Later we will be redoing the look of the site and possibly making changes to some of the dynamic data in MySQL.

So with a quick grep in our static pages I can get a list of files that have the word HSDB. The grep has to be careful, because we have Perl modules named HSDB:: as well, replacing that would mean bad things all around.

I found several different recommendations for replacing the text in a file using shell commands which piped data through sed, created new files and then overwrote the existing ones, but the simplest I've found is done with perl:

perl -i -pe 's/HSDB\ /TUSK\ /g'

If I was brave I would create a script that traversed the entire CVS trunk, replacing along the way, but I've decided to do it one directory at a time, so I can at least list the handful of files and verify that the replace is getting done correctly.

Posted by mike at August 12, 2003 4:35 PM