> -----Original Message-----
> From: Jeremy Eliosoff [mailto:[hidden email]]
> Sent: Friday, September 09, 2005 2:36 PM
> To: [hidden email] > Subject: delete lines NOT containing pattern.
> Hi there,
> I'm trying to delete all lines in my file that DON'T contain the word
> "parameter". I've tried this:
> but that deletes "parameter"-containing lines as well as all others.
> This confuses me because
> deletes only "parameter"-containing lines. I assumed that adding the
> \@! simply negates/inverts the pattern, matching all strings EXCEPT
> those that match the preceding atom. Please help!
Tim already gave you the best way, but let's see if I can explain why yours
The problem is that, as stated, your pattern matches *every* line, because
the \@! is a zero-length match, and there is nothing *outside* the
"exclusion" which must match. So, instead ...
You start with an anchor:
Then you want to *exclude* ANYTHING followed by the string:
Then grab anything left in the line:
This way you're anchored at both ends. You can leave off the last part if
you're just doing a search, but the idea is that you want to match the whole
line so you can delete it.
One more change before you substitute will work: $ is also a zero-length
atom, so replace it with \n, which causes the eol to also be deleted.