Date: Wed, 11 Nov 1998 19:35:18 +0000 From: Ben Smithurst <ben@scientia.demon.co.uk> To: Steve Friedrich <SteveFriedrich@Hot-Shot.com> Cc: "Alain G. Fabry" <fabry@panam.edu>, "freebsd-questions@FreeBSD.ORG" <freebsd-questions@FreeBSD.ORG> Subject: Re: find and replace within files. Message-ID: <19981111193518.A27115@scientia.demon.co.uk> In-Reply-To: <199811111743.MAA02129@laker.net> References: <199811111743.MAA02129@laker.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Steve Friedrich wrote: > On Wed, 11 Nov 1998 11:11:32 -0600, 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? > > Most experienced unix users, AFAIK, would use sed for this. I believe > sed is fairly difficult to master quickly from the man page and I think > your need is immediate. I suggest getting a book on sed from O'Reilly, > see www.ora.com Perl is quite nice for that too. For a whole tree, something like this may work: cd /where/your/files/are find . -type f | xargs perl -npi.bak -e 's/Name/Last_Name/g' then remove all the *.bak files when it's finished. Perhaps there's a similar way to do it with sed, I don't use that for anything complicated. -- Ben Smithurst ben@scientia.demon.co.uk send a blank message to ben+pgp@scientia.demon.co.uk for PGP key 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?19981111193518.A27115>