Date: Fri, 10 Dec 2004 02:54:39 +0200 From: Panagiotis Christias <christias@gmail.com> To: david.jenkins@gmail.com Cc: freebsd-questions@freebsd.org Subject: Re: Find & Replace string Message-ID: <e4b0ecef041209165435e21e24@mail.gmail.com> In-Reply-To: <57905.192.168.0.3.1102629017.squirrel@192.168.0.3> References: <019101c4de0e$dbdeb2d0$0200000a@SAGEAME> <20041209181336.GA3650@gentoo-npk.bmp.ub> <01cb01c4de1f$e8dbae00$0200000a@SAGEAME> <57905.192.168.0.3.1102629017.squirrel@192.168.0.3>
next in thread | previous in thread | raw e-mail | index | archive | help
On Thu, 9 Dec 2004 21:50:17 -0000 (GMT), David Jenkins <david.jenkins@gmail.com> wrote: > On Thu, 9 December, 2004 18:50, antenneX said: > > No, I want to interrogate several hundred thousand files throughout > > several thousand directories to find/replace a single string within > > each > > file found. The string may appear more than once in a file. > > Try the following (make sure you have a backup first ;)) > > perl -pi -e 's/STRING_TO_FIND/STRING_TO_REPLACE_WITH/g' filename > > e.g. to replace all instances of foo with bar in a file called test > you'd do: > > perl -pi -e 's/foo/bar/g' test > > You'd need to write a shell script to recursively run this on in each > subdirectory. Something like: find /mydir -type f -exec perl -pi -e 's/foo/bar/g' {} \; fast and effective. Panagiotis
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?e4b0ecef041209165435e21e24>