From owner-freebsd-questions Wed Nov 11 11:10:54 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id LAA21728 for freebsd-questions-outgoing; Wed, 11 Nov 1998 11:10:54 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from nick.cendant.com (nick.cendant.com [198.245.183.210]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id LAA21721 for ; Wed, 11 Nov 1998 11:10:52 -0800 (PST) (envelope-from rra@cms.cendant.com) Received: from mailhub.cuc.com (stratford.cuc.com [206.28.153.114]) by nick.cendant.com (8.8.5/8.9.2+) with ESMTP id OAA09827; Wed, 11 Nov 1998 14:10:26 -0500 (EST) Date: Wed, 11 Nov 1998 14:10:25 -0500 (EST) From: Rick Aliwalas X-Sender: rra@jakobako.oakview.cuc.com To: "Alain G. Fabry" cc: freebsd-questions@FreeBSD.ORG Subject: Re: find and replace within files. In-Reply-To: <037401be0d96$58d82b90$5531d5c6@earth.coserve.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG On Wed, 11 Nov 1998, Alain G. Fabry wrote: > Is there any way in FreeBSD that I can search in files for certain lines and > replace them with something else? > f.e. search for Name and replace with Last_Name > This needs to be done thruogh a whole directory tree. > Can you refer me to a command which will do this? > Thanks, > > Alain The below script will change all instances of the string "blue apple" to "red pear" in files under the directory /home/zzz. This may or may not help you write your own script. Make sure you backup your files and test your script on a bogus directory first! #!/bin/sh for file in `find /home/zzz` do if [ -f $file ] then sed 's/blue apple/red pear/g' $file > /tmp/$$ mv /tmp/$$ $file fi done To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message