[Linux-disciples] Grep oddity

Stephen R Laniel steve at laniels.org
Fri Apr 15 08:10:23 EDT 2005


I have a bunch of links of the form

<img src="dirname/[0-9]{3}\.jpg"

in an HTML file (call it filename.html). A client reports
that many of those links are showing up as missing
graphics in Internet Explorer. I'd prefer not to go
through those images one by one and figure out which ones
are missing.

So I'm trying to run a command like so:

grep -o "[0-9]{3}\.jpg" filename.html |xargs -i [ ! -e dirname/{} ] && echo "File {} does not exist"

That didn't work, which must be because I don't really
understand the [...] syntax. So I tried a hack:

grep -o "[0-9]{3}\.jpg" filename.html |xargs -i ls dirname/{} |grep -i 'no such file or directory' 2>&1 |grep -o '[0-9]{3}\.jpg'

But it's not working: it's displaying the entire line, not
just the matching bit (which is what the '-o' is supposed to
do). I've tried doing the last pipe also with sed (cutting
out everything from the beginning of the line up to
'[0-9]{3}\.jpg' and everything from that regex to the end of
the line), but that also fails.

There must be something really simple that I'm missing. Care
to help a clueless hacker?

-- 
Stephen R. Laniel
steve at laniels.org
+(617) 308-5571
http://laniels.org/


More information about the Linux-disciples mailing list