How to exclude a certain string in a search pattern

regular expressions

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?

Best Answer

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