Kadjo

SoftDev Journal

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

November 25th, 2008 by 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

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.