regex - find specific string but not when present in certain sentence -
i not sure if possible 1 regex line. want find sentence particular string not when present in specific sentence.
this grep 'word' file | grep -iv "particular sentence"
eg: input:
hello world foo here
foobar here there
foo bar
bar foo now
result should find word 'foo' not when sentence 'bar foo now': output:
hello world foo here
foobar here there
foo bar
is possible 1 line regex pattern?
you do:
^(?!bar foo now).*?foo.*$
which says "match line isn't "bar foo now", has "foo" in it".
however, you'll 1 match per line. if had:
hello foo foo.
that match, once entire line (as opposed twice, once each foo
).
Comments
Post a Comment