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

Popular posts from this blog

jasper reports - Fixed header in Excel using JasperReports -

media player - Android: mediaplayer went away with unhandled events -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -