Thursday, June 17, 2010

Search and Replace on Multiple Files

If you need to do a search and replace on multiple files in a directory this little one liner in perl does the job easily:

perl -p -i -e 's/oldstring/newstring/g' `grep -ril search *`

The grep makes sure only files that contain the old string are looked at by the perl script, that way you don't waste execution time - important on really large directory trees.

No comments:

Post a Comment