Main Menu
Key Concepts
Home
KnowledgeBase
PERL
Global Search and Replace in Unix
KnowledgeBase
PERL
Global Search and Replace in Unix
Global Search and Replace in Unix
The following code will perform a global search and replace in UNIX.
perl -p -i -e 's/oldstring/newstring/g' $(find . -name \*.fileext)
The parameters mean the following:
- -p = assume loop like -n but print line also, like sed (-n = assume "while () { ... }" loop around program)
- -i = edit files in place
- -e = precedes each line of the program (in this case 's/oldstring/newstring/g')
- $(find . -name \*.fileext) = do this for all file names matching *.fileext in the current drectory