Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 18 Dec 2001 11:50:43 +0100 (MET)
From:      Magnus B{ckstr|m <b@etek.chalmers.se>
To:        Anthony Atkielski <anthony@freebie.atkielski.com>
Cc:        FreeBSD Questions <freebsd-questions@freebsd.org>
Subject:   Re: Command to make modifications on multiple files
Message-ID:  <Pine.OSF.4.21.0112181148540.25097-100000@downy.etek.chalmers.se>
In-Reply-To: <007701c187af$8b564d40$0a00000a@atkielski.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, 18 Dec 2001, 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.
> 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.
> 

Using bourne shell, something like

for f in whatever/files/*.txt ; do
    sed -e 's/string to be replaced/new string/g' < ${f} > ${f}.tmp
    mv ${f}.tmp ${f}
done

// Magnus


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.OSF.4.21.0112181148540.25097-100000>