Wednesday, February 24, 2010

How to replace text in many files using single perl command

To replace text "localhost" to "localnet" in all files with extension text execute following
> perl -p -e "s/localhost/localnet/g" *.txt

To add new line after new text "localnet" use new line code \x0a
> perl -p -e "s/localhost/localnet\x0anew line/g" *.txt

To insert TAB in replaced text use code \x09
> perl -p -e "s/localhost/localnet\x0anew line\x09rest of line after tab/g" *.txt

No comments:

Post a Comment

Followers

About Me