//View Tip #167
» Local/remote webserver
» Close shell keeping all subprocess running
» Checksum directory recursively
» My code is compiling
Similar Tips
» SVN resolve all conflicts» Local/remote webserver
» Close shell keeping all subprocess running
» Checksum directory recursively
» My code is compiling
Latest tips by RSS
Click here to subscribe
Follow Shell-Fu on Twitter
Click here to follow
Follow Shell-Fu on identi.ca
Click here to follow
Find and replace recursively over several files:
The '.bak' will create copies of your original files with the .bak extension added incase of mistakes. Be careful of running this twice though as the backups will get overwritten.
perl -pi.bak -e "s/Bob/Steve/gi" *.html
The '.bak' will create copies of your original files with the .bak extension added incase of mistakes. Be careful of running this twice though as the backups will get overwritten.


Depending on the total number of files, you could do the same thing recursively like this:
perl -pi.bak -e 's/arse/tits/' $(find . -iname "*.html") # for a relatively small number of .html files
or
find . -iname '*.html' -exec perl -pi.bak -e '{}' \; # for a larger number of .html files
Actually, I think find has a way to modify -exec's behaviour so that it builds the list of files instead of execing for each match. I can't be bothered to look it up right now.