changing a file
Tom Christiansen
tchrist at convex.COM
Wed May 22 08:39:55 AEST 1991
>From the keyboard of KJB6 at psuvm.psu.edu:
:
:As a script, I would like to search a file and replace a string with
:another string. I know this can be done, but I have not figure out how to
:do it yet. Anyone have any suggestions. I think if I use awk or nawk somewhere
:along the line, I can get it done.
I believe the easiest, most flexible, and most powerful solution would
be along these lines:
perl -p -i.ORIG -e 's/old/new/g' file1 file2 ...
This will globally replace all instances of "old" with "new" in
all listed files, keeping a backup copy in file1.ORIG, etc. Omit
the ".old" part if you're brave enough.
--tom
--
Tom Christiansen tchrist at convex.com convex!tchrist
"So much mail, so little time."
More information about the Comp.unix.questions
mailing list