From owner-freebsd-questions Wed Apr 18 20:40:31 2001 Delivered-To: freebsd-questions@freebsd.org Received: from bcfw1d.bridge.com (bcfw1d.ext.bridge.com [167.76.159.31]) by hub.freebsd.org (Postfix) with ESMTP id 12A8437B43F for ; Wed, 18 Apr 2001 20:40:29 -0700 (PDT) (envelope-from tayers@bridge.com) Received: (from uucp@localhost) by bcfw1d.bridge.com (8.10.2/8.10.2) id f3J3fZE06820 for ; Wed, 18 Apr 2001 22:41:35 -0500 (CDT) Received: from (unknown [167.76.56.34]) by bcfw1d via smap (V2.1) id xma006763; Wed, 18 Apr 01 22:41:21 -0500 Received: from mnmailhost (mnmailhost.bridge.com [167.76.155.14]) by mail1srv.bridge.com (8.8.8/8.7.3) with SMTP id WAA18811 for ; Wed, 18 Apr 2001 22:40:12 -0500 (CDT) Received: from TAYERS-PC by mnmailhost (SMI-8.6/SMI-4.1) id XAA16999; Wed, 18 Apr 2001 23:40:10 -0400 To: questions@FreeBSD.ORG Subject: Re: OT:Use perl to substitute a string for another in many files References: <20010418190751.A25209@tortugas.irbs.com> From: Tim Ayers Date: 18 Apr 2001 22:40:08 -0500 In-Reply-To: <20010418190751.A25209@tortugas.irbs.com> Message-ID: Lines: 27 User-Agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG For an extra margin of safety you can give the -i option a parameter and then Perl will make backup copies of all the files. For example find blah.... | xargs perl -pi '.bak' -e 's/a-string/b-string/g' Hope you have a very nice day, :-) Tim Ayers (tayers@bridge.com) >>>>> "J" == John Capo writes: J> I use something like this: J> find blah.... | xargs perl -pi -e 's/a-string/b-string/g' J> John Capo J> Quoting Laurence Berland (laurence@isp.northwestern.edu): >> If I've got a bunch of files, that I can list using find, what is the best >> way, using perl, to substitute every instance of a string with a different >> string in all these files. >> >> Basically I want to run s/a-string/b-string/g in place on each file. >> >> Any ideas? I have already hosed some files messing this up once, and >> don't want to risk doing it again. >> J> To Unsubscribe: send mail to majordomo@FreeBSD.org J> with "unsubscribe freebsd-questions" in the body of the message To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message