Perl Recursive Search and Replace



Perl search and replace string. I use the following script to replace all occurrences of oldstring with newstring in all of the files in your current directory.

perl -p -i -e 's/oldstring/newstring/g' *

How do I replace in sub-directories as well?



Use Perl and Find as following. Perl before find or find before perl doesn't matter.

perl -p -i -e 's/oldstring/newstring/g' `find ./ -name *.html`

or

find ./ -exec perl -p -i -e ’s/oldstring/newstring/g’ {} \;

Tony