Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 7 Jan 1997 17:46:22 -0800 (PST)
From:      John-Mark Gurney <jmg@nike.efn.org>
To:        rg@gds.de
Cc:        freebsd-isp@freebsd.org
Subject:   Re: grep & replace
Message-ID:  <Pine.NEB.3.95.970107174345.311a-100000@hydrogen.nike.efn.org>
In-Reply-To: <199701080055.BAA03700@gds.de>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, 8 Jan 1997 rg@gds.de wrote:

> Hallo,
> 
> I have to replace one special word in about one hundred files. The 
> expression could be several time in some files.
> 
> Is there something like grep that would not only find these 
> expressions but also replace them by the new one?

yep... it's sed:
#!/bin/sh -
for i in $*; do
	sed -e 's/word/newword/g' < $i > /tmp/$$.sed.out
	mv /tmp/$$.sed.out $i
done

that will replace all of `word' with `newword' in all the files listed on
the command line.... hope this helps... ttyl..

John-Mark

gurney_j@efn.org
http://resnet.uoregon.edu/~gurney_j/
Modem/FAX: (541) 683-6954   (FreeBSD Box)

Live in Peace, destroy Micro$oft, support free software, run FreeBSD (unix)




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