Seemingly simple task. I need to display a line if a match is not found. Or, said another way, I need to not display a line if a match is found. I suspect this involves a look ahead assertion of some kind but can't figure out how.
I've tried finding a match and then trying to negate it with ^. But that doesn't seem to work. Also tried finding a matc开发者_开发知识库h and putting {0} next to it: (wordhere){0}
You can indeed use a negative lookahead. E.g.
^(?!something$).*$
will match anything besides "something".
Note that it may however be much more appropriate and better to read if you do a positive match and use control structures like if not ...
to define which line is printed and which line is not.
If you can use grep,
grep -v <expr>
does what you want.
精彩评论