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

Snippets has posted 5883 posts at DZone. View Full User Profile

Multiple File Search And Replace

07.25.2005
| 38374 views |
  • submit to reddit
        
perl -pi -w -e 's/search/replace/g;' *.txt

Bear in mind what's between the single quotes after the -e option is a line of Perl code and the search argument is a regular expression, so some characters will have special meanings. You can escape special characters (like the forward-slash, dot, caret, dollar sign, and so on) by preceeding them with a back-slash.    

Comments

Snippets Manager replied on Sat, 2010/08/14 - 11:00am

Here is a good Perl script about that purpose: http://website-security.info/tools/find-and-replace-script

Snippets Manager replied on Wed, 2010/08/11 - 8:50am

Sorry, forgotten -l perl -pi -w -e 's/search/replace/g;' `grep -l search *.txt` to avoid changing mtime of files you don't change. Jan.

Snippets Manager replied on Wed, 2010/08/11 - 8:50am

perl -pi -w -e 's/search/replace/g;' *.txt I would use perl -pi -w -e 's/search/replace/g;' `grep search *.txt` to avoid changing mtime of files you don't change. Jan.