Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

zero-width negative look-ahead in UNIX shell? 1

Status
Not open for further replies.

bootn3ck

Programmer
Aug 12, 2004
2
GB
Hello,

i have the following problem.

Say a file has the following 2 lines

<img src="spacer.gif" blablabla alt=""><img src="spacer.gif" someMoreGarbage>

<img src="spacer.gif" blablabla><img src="spacer.gif" someMoreGarbage>

how do i search for the lines which DO NOT have the "alt" attribute following the "spacer.gif"?

Now, i know this is called "zero-width negative look-ahead assertion" in Perl, but i can't seem to get it to work in Perl do to the greedy and non-greedy operators not really functioning in the way i expect.
Is there any way of doing this with SED or grep (or its variants)?

Any help would be great!
 
Something like this ?
fgrep '<img src="spacer.gif"' /path/to/file | fgrep -v 'alt='
Or this ?
awk '/spacer.gif/{if($0!~/alt=/)print}' /path/to/file

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Hey thanks!
It seems to work fine. I think the special bit is the -v option with fgrep. Will remember for next time :)

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top