> :
> : VZ> I want to grep on 'foo' NOT followed by 'bar'. So line 1, 3
> : VZ> and 4 would match. (line 3 has a foo NOT followed by bar)
> :
> : Negating a regular expression is tricky business. For this relatively
> : easy example, you need something like:
> :
> [example deleted]
> : As you can see, the regexp will quickly get very complicated. Here's
> : one for regular, not followed by expression:
> :
> [...]
> It's much easier to grep twice:
> grep foo filename | grep -v foobar
This *almost* does what the original poster asked for, but not quite.
Note example [3] below from the original query: it is supposed to
succeed, but it will fail in the above "grep twice" solution.
Quote:>I want to use some grep command to match lines that contain
>some word and NOT followed by another.
>Examples:
> [1] ^foo$
> [2] ^foobar$
> [3] ^foo foobar$
> [4] ^fooba$
>I want to grep on 'foo' NOT followed by 'bar'. So line 1, 3 and
>4 would match. (line 3 has a foo NOT followed by bar)
With the stipulation that [3] succeeds, the longer, more compilcated
solution seems, unfortunately, to be the only way if you are
restricting yourself to 'grep' (and 'egrep'). If you are willing to
use 'awk' or 'perl', you might be able to come up with something a bit
more "elegant".
--
Lloyd Zusman 01234567 <-- The world famous Indent-o-Meter.
To get my PGP public key automatically mailed to you, please send me email
with the following string either as the subject or on a line by itself:
mail-request: public key