From owner-freebsd-questions Sun Jan 23 23: 9: 3 2000 Delivered-To: freebsd-questions@freebsd.org Received: from isy.liu.se (isy.liu.se [130.236.48.10]) by hub.freebsd.org (Postfix) with ESMTP id 7CA5515825 for ; Sun, 23 Jan 2000 23:08:45 -0800 (PST) (envelope-from mj@isy.liu.se) Received: from lagrange.isy.liu.se (lagrange.isy.liu.se [130.236.49.127]) by isy.liu.se (8.9.1/8.9.1) with ESMTP id IAA19072; Mon, 24 Jan 2000 08:08:27 +0100 (MET) Message-ID: X-Mailer: XFMail 1.3 [p0] on FreeBSD X-Priority: 3 (Normal) Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: 8bit MIME-Version: 1.0 In-Reply-To: <200001211709.JAA06271@www.geocrawler.com> Date: Mon, 24 Jan 2000 08:08:26 +0100 (CET) From: Micke Josefsson To: Juan Kuuse Subject: RE: UNIX search n replace Cc: freebsd-questions@FreeBSD.ORG Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On 21-Jan-00 Juan Kuuse wrote: > This message was sent from Geocrawler.com by "Juan Kuuse" > > Be sure to reply to that address. > > More a common UNIX question than a FreeBSD topic: > > grep > to search a keyword multiple files > > How do I search and replace one keyword for > another in multiple files, any suggestions? > > Thanks in advance! > > Juan Kuuse > kuuse@quik.guate.com > > Geocrawler.com - The Knowledge Archive > > > To Unsubscribe: send mail to majordomo@FreeBSD.org > with "unsubscribe freebsd-questions" in the body of the message Use 'sed' like this: sed -e 's/SEARCHFOR/REPLACEWITH/g' infile outfile You can let infile[s] be produced by 'find .' if you like or have the file names in a file... A little sh-programming like this maybe: $for i in `find . -name "blah?.txt"`; do >echo sed -e 's/hello/HELLO/g' $i >$i.tmp >echo mv -f $i.tmp $i >done The '>':s are sh's prompt when doing a multiline command. Preceeding each line 'that does something' with echo is useful when trying out the command. Just remove them when you're confident the script does what it should. (It might be a good idea to try it in a temporary directory first...) Cheers, /M ---------------------------------- Michael Josefsson, MSEE mj@isy.liu.se This message was sent by XFMail running on FreeBSD 3.1 ---------------------------------- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message