[oclug] sed, awk, perl, or ...?
Raymond Wood
raywood at magma.ca
Fri Mar 1 10:01:42 EST 2002
On Wed, Feb 27, 2002 at 01:18:15AM -0500, Joe Burpee remarked:
> On Tue, 26 Feb 2002 at 22:57:53 -0600, Raymond Wood wrote:
> > o Open and search through a bunch of HTML files and locate all
> > strings of the form 'image*_' (where the * represents either 2
> > or 3 numeric characters).
> > o increment the 2 or 3 digit number by a value of '1'.
> > o optionally, do this recursively through several
> > sub-directories.
> find /some/dir -name \*.html -print0 |
> xargs -0 perl -pi.bak -e 's/image(\d{2,3})_/image@{[$1+1]}_/g'
>
> This assumes you want to do all .html files below directory /some/dir.
> The -print0 and -0 avoid possible problems with weird characters like
> spaces in filenames. Perl's -i option causes the files to be processed
> one by one, rather than concatenated; also the original files are backed
> up with suffix .html.bak. The xargs utility is a handy way to break up
> argument lists into manageable chunks, and is probably safer and more
> efficient than alternatives such as a `for' loop.
>
> For details see the man pages perlrun, perlre, and perlop; also info
> pages for find and xargs.
Joe, this 1-liner script works like a charm (but you doubtless knew that
already :) I am in a state of amazement...
Thanks to you and others for feedback received.
Cheers,
Raymond
--
Raymond Wood XIST Information Services & Technology Inc.
Ottawa, Ontario phone: (613)234-9621 X233 fax: (613)234-9564
http://xist.com raymond.wood at xist.com 1-888-ASK-XIST
More information about the OCLUG
mailing list