0

There are several exception messages in catalina.out file of tomcat server just like -

java.lang.NullPointerException

org.springframework.beans.factory.BeanCreationException

java.lang.RuntimeException

java.io.FileNotFoundException

We want to grep all exception error message except “java.io.FileNotFoundException” string. Tried with below command but it’s not working.

cat catalina.out | grep '.*(?<\!=java.io.FileNotFound)Exception\*.)'

Can you please help to find out the correct command?

squillman
  • 37,618
  • 10
  • 90
  • 145

2 Answers2

1

Try a multi-stage grep: cat <file> | grep Exception | grep -v java.io.FileNotFoundException

John
  • 8,920
  • 1
  • 28
  • 34
0

you can concatenate with multiple grep statements as @John suggested in the other answer or for instance use awk e.g.

awk '/Exception/ && !/java.io.FileNotFoundException/' catalina.out

on your sample this will produce

$ awk '/Exception/ && !/java.io.FileNotFoundException/' catalina.out 
java.lang.NullPointerException
org.springframework.beans.factory.BeanCreationException
java.lang.RuntimeException

This basically says; match everything that has Exception string; and NOT java.io.FileNotFoundException

Hrvoje Špoljar
  • 5,162
  • 25
  • 42