From owner-freebsd-questions Tue Dec 18 3: 3: 5 2001 Delivered-To: freebsd-questions@freebsd.org Received: from mailc.telia.com (mailc.telia.com [194.22.190.4]) by hub.freebsd.org (Postfix) with ESMTP id 73FFA37B41D for ; Tue, 18 Dec 2001 03:03:00 -0800 (PST) Received: from d1o913.telia.com (d1o913.telia.com [195.252.44.241]) by mailc.telia.com (8.11.6/8.11.6) with ESMTP id fBIB2xY23779 for ; Tue, 18 Dec 2001 12:02:59 +0100 (CET) Received: from ertr1013.student.uu.se (h185n2fls20o913.telia.com [212.181.163.185]) by d1o913.telia.com (8.8.8/8.8.8) with SMTP id MAA15772 for ; Tue, 18 Dec 2001 12:02:57 +0100 (CET) Received: (qmail 1508 invoked by uid 1001); 18 Dec 2001 11:02:56 -0000 Date: Tue, 18 Dec 2001 12:02:56 +0100 From: Erik Trulsson To: Jon Molin Cc: Anthony Atkielski , FreeBSD Questions Subject: Re: Command to make modifications on multiple files Message-ID: <20011218110256.GA1464@student.uu.se> Mail-Followup-To: Jon Molin , Anthony Atkielski , FreeBSD Questions References: <007701c187af$8b564d40$0a00000a@atkielski.com> <3C1F1C07.79B38414@resfeber.se> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3C1F1C07.79B38414@resfeber.se> User-Agent: Mutt/1.3.24i Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Tue, Dec 18, 2001 at 11:35:51AM +0100, Jon Molin wrote: > Anthony Atkielski wrote: > > > > There is probably a UNIX command that allows me to replace strings in > > multiple files all at once, but I can't remember what the name of it would > > be, and this being UNIX, I'm sure the name is not the least bit intuitive. > > no i bet you'd benefit copying them to NT and replacing them there, it's > probaly a perfect name like 'replace strings in multiple files.exe' > that will do the trick for you. No need to be rude. If you don't know the answer just don't bother with snide comments like this. It is a fact that command names in Unix are often not very intuitive. > > > > Any suggestions on what command would do this? Sort of like grep, but with > > an option to replace a string as well as just finding it. You might want to look at sed or awk or maybe perl. Of these perl is probably the easiest to do it in. (This is the cue for somebody to jump in and say how evil perl is and that it is much easier to do it in . :-) ) WIth perl you might do it something like: [Warning! Untested code follows!] perl -pie 's/searchregex/replacestring/g' file1 file2 file3 ( The -p option tells perl to read one line at a time from the input files, do the command, and output the result. The -i option tells perl to do it inplace rather than writing to stdout, and -e tells perl that the next argument is the actual code and not the name of a file containing the code. ) For more information please read the documentation for perl, 'man perl' is a good place to start. -- Erik Trulsson ertr1013@student.uu.se To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message