[wplug] simple regex
Bob Schmertz
rschmertz at speakeasy.net
Wed Jun 25 19:55:39 EDT 2003
Duncan Hutty wrote:
>>
>>I'm trying to parse a file for lines that do not contain the '@'
>> character. Some lines of the input contain this character, some do
>> not.
>>
>>grep '[^@]' prints all lines, regardless of whether they include '@'
>>or not.
>
Whereupon Mike Kuentz (2) incurred the wrath of Bob on Jun 25, by saying
>$ grep -v '@' filename
>
>Should do it. -v gives you the inverse of what you are looking for. In
>your expression the ^ is interpreted as the beginning of the line. It's not
><NOT> as I think you were trying.
To which Bob Schmertz now responds:
In this context, it *is* <NOT>. But the reason it doesn't work as you
expected is because it means "show me lines which contain at least one
character which is not '@'. Thus the line
@@@@@@@@@@@@@t@@@@@@@@@@@
would match because the 't' matches the 'not a @' requirement.
Another thing you could do would be
grep '^[^@]*$'
which would mean "the whole line should consist of characters which are
not @". But grep -v is easier, especially when you want to exclude more
complex things.
--
Cheers,
Bob Schmertz
More information about the wplug
mailing list