From owner-freebsd-questions Wed Nov 11 13:29:06 1998 Return-Path: Received: (from majordom@localhost) by hub.freebsd.org (8.8.8/8.8.8) id NAA04963 for freebsd-questions-outgoing; Wed, 11 Nov 1998 13:29:06 -0800 (PST) (envelope-from owner-freebsd-questions@FreeBSD.ORG) Received: from scientia.demon.co.uk (scientia.demon.co.uk [212.228.14.13]) by hub.freebsd.org (8.8.8/8.8.8) with ESMTP id NAA04951 for ; Wed, 11 Nov 1998 13:28:55 -0800 (PST) (envelope-from ben@scientia.demon.co.uk) Received: from ben by scientia.demon.co.uk with local (Exim 2.053-bcps #6) id 0zdg2w-00074E-00; Wed, 11 Nov 1998 19:35:18 +0000 Date: Wed, 11 Nov 1998 19:35:18 +0000 From: Ben Smithurst To: Steve Friedrich Cc: "Alain G. Fabry" , "freebsd-questions@FreeBSD.ORG" Subject: Re: find and replace within files. Message-ID: <19981111193518.A27115@scientia.demon.co.uk> References: <199811111743.MAA02129@laker.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii In-Reply-To: <199811111743.MAA02129@laker.net> User-Agent: Mutt/0.94.12i (FreeBSD/3.0-CURRENT) Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG 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