How to do a search and replace in multiple files using perl and linux
So you’ve got 100 files in a directory and you want to replace the string “foo” with “bar”. Stop before you waste your time opening up every single file and making the change, you can make all of the changes with a single line of perl.
perl -pi -w -e 's/foo/bar/g' *\.php
On his blog, Liam Delahunty explains what each of the following command line switches means.
-e means execute the following line of code.
-i means edit in-place
-w write warnings
-p loop
There you have it – a nice and easy Perl solution that should save you tons of time.

Leave a Reply