About This Journal
24 June 2007 by Jojo Makiling
Technical concerns tend to find a solution as long as there are good people working on them. And Linux has the very best. - Linus Torvalds
Search and Replace text in all files in a folder and its subfolders
pepesmith
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;
Posted in Miscellaneous |
No Comments »
Leave a Comment