From owner-freebsd-questions@FreeBSD.ORG Thu Dec 9 21:50:01 2004 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 51D1716A4CE for ; Thu, 9 Dec 2004 21:50:01 +0000 (GMT) Received: from gateway.unixusers.co.uk (unixusers.co.uk [82.133.118.138]) by mx1.FreeBSD.org (Postfix) with ESMTP id EE1BD43D5E for ; Thu, 9 Dec 2004 21:50:00 +0000 (GMT) (envelope-from david.jenkins@gmail.com) Received: by gateway.unixusers.co.uk (Postfix, from userid 80) id ED5565C58; Thu, 9 Dec 2004 21:50:17 +0000 (GMT) Received: from 192.168.0.3 (SquirrelMail authenticated user david); by unixusers.co.uk with HTTP; Thu, 9 Dec 2004 21:50:17 -0000 (GMT) Message-ID: <57905.192.168.0.3.1102629017.squirrel@192.168.0.3> In-Reply-To: <01cb01c4de1f$e8dbae00$0200000a@SAGEAME> References: <019101c4de0e$dbdeb2d0$0200000a@SAGEAME> <20041209181336.GA3650@gentoo-npk.bmp.ub> <01cb01c4de1f$e8dbae00$0200000a@SAGEAME> Date: Thu, 9 Dec 2004 21:50:17 -0000 (GMT) From: "David Jenkins" To: "antenneX" User-Agent: SquirrelMail/1.4.3a X-Mailer: SquirrelMail/1.4.3a MIME-Version: 1.0 Content-Type: text/plain;charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal cc: Nathan Kinkade cc: freebsd-questions@freebsd.org Subject: Re: Find & Replace string X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list Reply-To: david.jenkins@gmail.com List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Dec 2004 21:50:01 -0000 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. Cheers, David