[vox-tech] Using awk or perl to find and replace
Foo Lim
foo at joshuatree.cs.ucdavis.edu
Wed Nov 24 09:56:26 PST 2004
On Wed, 24 Nov 2004, Ken Bloom wrote:
> On Wed, Nov 24, 2004 at 08:57:03AM -0800, Trevor M. Lango wrote:
>
> > > s/h\.(.*?)\.JPG/$1.h.JPG/g;
> > >
> > > instead, so it will minimal match instead of do a greedy match.
> >
> > Okay I am not having any success. Perhaps I need to be more specific - I am
> > trying to scan through html files to replace the image references in lines
> > like this one:
> >
> > <img align=right src="/IMAGES/C/h.I-LP-CEUR-AD.003.jpg"
> >
> > In this particular example, I need to replace:
> >
> > h.I-LP-CEUR-AD.003.jpg
> >
> > with:
> >
> > I-LP-CEUR-AD.003.h.jpg
> >
> > Thank you for your responses!
>
> Capitalization counts. If the files are named with a .jpg, then your
> regexp pattern has to say .jpg. If the files are named with a .JPG,
> then your regexp pattern has to say .JPG. There is a flag that you can
> add at the end (were the g is) to do a case insensitive match, but not
> to do a case insensitive, but not to make the replacement string case
> insensitive.
Add an i to the end of the statement:
s/h\.(.*?)\.JPG/$1.h.JPG/gi;
However, this will match files that start with a lowercase h as well as an
uppercase H. If that's fine, then this regex will do the job.
FL
More information about the vox-tech
mailing list