Is it possible, using grep, to search for instances of John Smith
but exclude instances of Mr John Smith
?
Ubuntu – grep for string not preceded by another string
grepregex
grepregex
Is it possible, using grep, to search for instances of John Smith
but exclude instances of Mr John Smith
?
Best Answer
This could be solved using a regular expression with negative lookbehind (which is experimentally supported in
grep
as pointed out by the comment from arrange):Since the support is just experimental, you might want to use
perl
instead: