Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!convex!usenet From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.questions Subject: Re: changing a file Message-ID: <1991May21.223955.5516@convex.com> Date: 21 May 91 22:39:55 GMT References: <91141.140213KJB6@psuvm.psu.edu> Sender: usenet@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 20 Nntp-Posting-Host: pixel.convex.com From the keyboard of KJB6@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@convex.com convex!tchrist "So much mail, so little time."