Monthly Archives: November 2008

Search and Replace text in all files in a folder and its subfolders

Tip for those who are lazy enough to use vi and do :%/origstring/newstring/g on each files.

To replace all string occurence:

find /your/home/dir -name "*.txt" | xargs perl -pi -e 's/origstring/newstring/g'

To replace the first occurance:

find /your/home/dir -name "*.txt" | xargs perl -pi -e 's/origstring/newstring/'

To replace all files in a folder:

for arg in `ls -C1`; do perl -pi -e 's/origstring/newstring/g'; done;