I am currently matching for \"Exception\" from a file, and output 10 lines before and after using:
grep -C 10 \"[.*Exception\"
If you have grep -P
you can specify a negative lookbehind assertion.
grep -C 10 -P '\[.*(?<!AAA|BBB)Exception'
If your positive match pattern Exception is a word i.e not preceded/followed by other alphabets then you can use word-boundary.
$ grep -C 10 '\<NullPointerException\>\|\<SessionTimeoutException\>'