DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world
One-line Shell Script For Find And Replace
An equivalent of the other find-replace, except it's a one-liner that generates no temp files, and is more flexible:
perl -pi -e 's/find/replace/g' *.txt
Or, to change matching files in a hierarchy:
find . -name '*.txt' |xargs perl -pi -e 's/find/replace/g'





Comments
Snippets Manager replied on Sun, 2010/03/21 - 6:21am
Snippets Manager replied on Wed, 2009/02/25 - 12:43pm
find . -name '*.txt' -type f -exec perl -pi -e 's/find/replace/g' {} \;to make sure you're working on a normal file.Snippets Manager replied on Wed, 2009/02/25 - 12:43pm
find . -name '*.txt' -exec perl -pi -e 's/find/replace/g' {} \;Then it doesn't matter what the filename has in it :-)Snippets Manager replied on Mon, 2012/03/05 - 3:46am
Snippets Manager replied on Wed, 2007/10/03 - 9:25am
find . -name '*.txt' -print0 |xargs -0 perl -pi -e 's/find/replace/g'