The 2007-08-11 at 15:35 by Loïc d'Anterroches filed under News.
This is more as a personal reminder:
Find all the files recursively containing the string StringToSearch:
find . | xargs grep 'StringToSearch'
Find and replace all the strings in the files (in place replacement):
perl -pi -e "s/OldString/NewString/g;" ./*.py
or to scan one level deeper in the folders:
perl -pi -e "s/OldString/NewString/g;" ./*/*.py
Comments from readers
a bit more said:
Find all the files recursively containing the string StringToSearch:
grep -R . 'StringToSearch'
Find and replace all the strings in the files (in place replacement):
sed -i "s/OldString/NewString/g;" ./*.py
or to scan one level deeper in the folders:
sed -i "s/OldString/NewString/g;" ./*/*.py
Loïc said:
Thanks for these versions, I really need to a look a little bit more at the man pages of sed and grep!
Jeremiah said:
rpl - search and replace utility is great for these tasks.
http://www.laffeycomputer.com/rpl.html