Date: Wed, 11 Nov 1998 23:14:46 -0600 From: Jon Hamilton <hamilton@pobox.com> To: Rick Aliwalas <rra@cms.cendant.com> Cc: "Alain G. Fabry" <fabry@panam.edu>, freebsd-questions@FreeBSD.ORG Subject: Re: find and replace within files. Message-ID: <199811120515.VAA25899@hub.freebsd.org> In-Reply-To: Your message of "Wed, 11 Nov 1998 14:10:25 EST." <Pine.GSO.4.05.9811111356120.11939-100000@jakobako.oakview.cuc.com>
next in thread | previous in thread | raw e-mail | index | archive | help
In message <Pine.GSO.4.05.9811111356120.11939-100000@jakobako.oakview.cuc.com>, Rick Aliwalas wrote: } On Wed, 11 Nov 1998, Alain G. Fabry wrote: } } > Is there any way in FreeBSD that I can search in files for certain lines an } d } > 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! Be aware that it will also mangle permissions and will fail for filenames with whitespace in them. This kind of thing is relatively straightforward with perl5; if you'd prefer to stick to "stock" tools, an ed script would probably be more advisable if you care about these issues. } #!/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 -- Jon Hamilton hamilton@pobox.com 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?199811120515.VAA25899>