From owner-freebsd-questions@FreeBSD.ORG Thu Dec 9 18:50:28 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 B3C0A16A4D2 for ; Thu, 9 Dec 2004 18:50:28 +0000 (GMT) Received: from ylpvm29.prodigy.net (ylpvm29-ext.prodigy.net [207.115.57.60]) by mx1.FreeBSD.org (Postfix) with ESMTP id 03D8943D5C for ; Thu, 9 Dec 2004 18:50:12 +0000 (GMT) (envelope-from antennex@swbell.net) Received: from SAGEAME (adsl-65-68-247-73.dsl.crchtx.swbell.net [65.68.247.73])iB9Io68r008873; Thu, 9 Dec 2004 13:50:07 -0500 Message-ID: <01cb01c4de1f$e8dbae00$0200000a@SAGEAME> From: "antenneX" To: "Nathan Kinkade" References: <019101c4de0e$dbdeb2d0$0200000a@SAGEAME> <20041209181336.GA3650@gentoo-npk.bmp.ub> Date: Thu, 9 Dec 2004 12:50:08 -0600 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 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: antenneX List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Dec 2004 18:50:29 -0000 From: "Nathan Kinkade" To: "antenneX" Cc: Sent: Thursday, December 09, 2004 12:13 PM Subject: Re: Find & Replace string > In a website of 1.GB+ with several hundred thousand files, I need to > interrogate all files to replace a single string like "oldone.010" with > "newone.011" > > What's the best way to do this? > > Thanks in advance! > > Best regards, > > Jack L. Stone Are you talking about changing the name of the file itself, or a string within the file? If it's the former then a shell for loop work. Maybe something like: $ for file in $(find /somedir -name "*.010"); \ do mv $file $(echo $file | sed -e 's/oldone/newone'); \ done If the latter, then using perl, perhaps with the -e -i switches, might work well. man perlrun(1) for some tips. Nathan ------------------------------------------------------------- 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. Thanks for the reply....