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
Ahsan Gill replied on Fri, 2013/05/10 - 6:40am
event security newry event security lisburn event security londonderry event security belfast event security armagh event security county-armagh event security swansea event security st asaph event security newport event security cardiff event security bangor event security stirling event security perth event security inverness event security glasgow event security edinburgh
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'