Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 Nov 1998 14:10:25 -0500 (EST)
From:      Rick Aliwalas <rra@cms.cendant.com>
To:        "Alain G. Fabry" <fabry@panam.edu>
Cc:        freebsd-questions@FreeBSD.ORG
Subject:   Re: find and replace within files.
Message-ID:  <Pine.GSO.4.05.9811111356120.11939-100000@jakobako.oakview.cuc.com>
In-Reply-To: <037401be0d96$58d82b90$5531d5c6@earth.coserve.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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



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