From owner-freebsd-questions@FreeBSD.ORG Fri Dec 10 00:54:41 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 EED2116A4E9 for ; Fri, 10 Dec 2004 00:54:41 +0000 (GMT) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.197]) by mx1.FreeBSD.org (Postfix) with ESMTP id 5E43943D39 for ; Fri, 10 Dec 2004 00:54:41 +0000 (GMT) (envelope-from christias@gmail.com) Received: by rproxy.gmail.com with SMTP id a41so686346rng for ; Thu, 09 Dec 2004 16:54:40 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:references; b=E1GvIuY9KRkWV8k6e/WKtNyC/KI5ApwCPnRVY753yaYg1O+lWQkAk4z03yQ5ynb66qyTVp2p6T3RFb35U+RtQdbAOjIDV7GdbXPiz+pWvFDKankO/6g78Bm4zXQtNKXatxOL2KyejVhj+ZSiSxMkTFeRVXbFObs/fLVNYch6me0= Received: by 10.38.67.49 with SMTP id p49mr1252779rna; Thu, 09 Dec 2004 16:54:39 -0800 (PST) Received: by 10.38.165.65 with HTTP; Thu, 9 Dec 2004 16:54:39 -0800 (PST) Message-ID: Date: Fri, 10 Dec 2004 02:54:39 +0200 From: Panagiotis Christias To: david.jenkins@gmail.com In-Reply-To: <57905.192.168.0.3.1102629017.squirrel@192.168.0.3> Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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> cc: antenneX 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: Panagiotis Christias List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Dec 2004 00:54:42 -0000 On Thu, 9 Dec 2004 21:50:17 -0000 (GMT), David Jenkins 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