From owner-freebsd-questions@FreeBSD.ORG Wed Jul 23 13:21:25 2003 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 1195837B404 for ; Wed, 23 Jul 2003 13:21:25 -0700 (PDT) Received: from webserver.get-linux.org (adsl-64-161-78-226.dsl.lsan03.pacbell.net [64.161.78.226]) by mx1.FreeBSD.org (Postfix) with SMTP id 210C743FBD for ; Wed, 23 Jul 2003 13:21:22 -0700 (PDT) (envelope-from oremanj@webserver.get-linux.org) Received: (qmail 1971 invoked by uid 1000); 23 Jul 2003 20:21:46 -0000 Date: Wed, 23 Jul 2003 13:21:46 -0700 From: oremanj@get-linux.org To: questions@freebsd.org Message-ID: <20030723202146.GD1504@webserver> References: <1gf6uzxb9h9ir.1okxodxnyrkv2.dlg@40tude.net> <20030723202040.GC1504@webserver> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20030723202040.GC1504@webserver> User-Agent: Mutt/1.4.1i cc: scott@sremick.net Subject: Re: search & replace on multiple files X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jul 2003 20:21:25 -0000 On Wed, Jul 23, 2003 at 01:20:40PM -0700 or thereabouts, oremanj@get-linux.org wrote: > On Wed, Jul 23, 2003 at 10:56:19AM -0400 or thereabouts, Scott I. Remick wrote: > > Hello... I'm trying to figure out a way to pull off the following: > > > > I have a subdir with many different sorts of text files (some nested in > > additional subdirs, so recursion would be necessary) that need to have a > > search & replace done on them. What's a quick way to script a global search > > & replace on many/all text files in nested subirs? > > Hard way (tested): > > #!/usr/bin/env perl > > use File::Find; > > find sub { > -f $_ or return; > my $file = $_; > my $filebak = "${file}~"; > rename $file, $filebak or die "Can't rename $file to $filebak: $!\n"; > open FILEBAK, $filebak or die "Can't open $filebak: $!\n"; > open FILE, ">$file" or die "Can't write to $file: $!\n"; > while () { > > # Replace OLD with the "search for" -- a regexp > # Replace NEW with the "replace with" > s/OLD/NEW/g; > > print FILE $_; > } > }, "."; > > # end replace.pl > > Easy way (not tested): > > find . -type f | perl -pi~ -e 's/OLD/NEW/g;' ^ OOPS, sorry, there should be an `xargs' here -- Josh > > -- Josh > > > > > Thanks! > > > > _______________________________________________ > > freebsd-questions@freebsd.org mailing list > > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org" > _______________________________________________ > freebsd-questions@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-questions > To unsubscribe, send any mail to "freebsd-questions-unsubscribe@freebsd.org"