I am currently matching for "Exception" from a file, and output 10 lines before and after using:
grep -C 10 "[.*Exception"
But now I wish to exclude certain specific Exceptions, say AAAException and BBBException, how could I do it? It can be done via
grep -v "AAAException" | grep -C 10 "[.*Exception"
But if within the file, I have AAAException within 10 lines from some other Exception, that line would not be included in the output, which is not what I want. How can I not match for AAAException, but if it occurred within 10 lines from some other Exception, it will still be included in the output?
If you have grep -P
you can specify a negative lookbehind assertion.
grep -C 10 -P '\[.*(?<!AAA|BBB)Exception'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With