easy way to change string in multiple files?

Steven Elling ellings at kcnet.com
Sun Oct 6 10:26:13 CDT 2002


On Saturday 05 October 2002 21:17, Chris Hoelscher wrote:
> Looking for an easy way to change 'string.a' to 'string.b' in a set of
> files within one directory.  I know I can find all the lines with grep,
> but is there a command I can pipe the grep to to change the files?
>
> Thanks -
> Chris.
>
>
>
>

You can do the following if you have perl on your system.

perl -pi -e 's/string.a/string.b/g' file-name

or

perl -pi -e 's/string.a/string.b/g' shell-wildcard

If you want to make a backup copy of the files -- with a '.bak' extension
added on -- do the following:

perl -pi.bak -e 's/string.a/string.b/g' file-name

or

perl -pi.bak -e 's/string.a/string.b/g' shell-wildcard

More info can be found by doing a 'man perlrun' at the console.

This will use regular expresions and to get info on how to use them do a 'man 
7 regex' or 'info regex'.  Hopefully one of those will provide you enough 
info.




More information about the Kclug mailing list