Gossamer Forum
Home : General : Perl Programming :

Search and Replace

Quote Reply
Search and Replace
Hi... Can anyone tell me a short code to do the following :

Take a text file and look for a certain word and replace it with a different word and then save the text file, over writing the existing file.

Quote Reply
Re: [pcmike] Search and Replace In reply to
Hello PcMike,

Short code ?

perl -pi.bak -e s/oldtext/newtext/g file.txt [ case sensitive ]

will find "oldtext" and replace with "newtext"

perl -pi.bak -e s/oldtext/newtext/gi file.txt [ case insensitive ]

and both will also create file.txt.bak

thanks cornball