grep Exception but exclude specific Exception

后端 未结 2 1094
眼角桃花
眼角桃花 2021-01-13 08:05

I am currently matching for \"Exception\" from a file, and output 10 lines before and after using:

grep -C 10 \"[.*Exception\"

相关标签:
2条回答
  • 2021-01-13 08:41

    If you have grep -P you can specify a negative lookbehind assertion.

    grep -C 10 -P '\[.*(?<!AAA|BBB)Exception' 
    
    0 讨论(0)
  • 2021-01-13 08:49

    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\>'
    
    0 讨论(0)
提交回复
热议问题