Skip to content
Advertisement

Find all jvm log files with “Exception” message and list the count of uniq exceptions

I have a list of jvm log files that I need to search for Exception and then list the count of each unique exception .

04/12 02:20:45.183 00243577 000                  java.util.concurrent.ExecutionException 
04/12 02:20:45.184 00243577 000                  java.lang.IllegalArgumentException 
04/12 02:20:45.184 00243578 000                  java.lang.RuntimeException 
04/12 02:20:45.185 00243579 000                  java.lang.RuntimeException 

Following is the command I am using:

find . -name "*jvm*"|xargs grep " 000 " | grep -nc "Exception" 

This gives me output of total exception count in each file :

./jvm1.104.log:1
./jvm1.108.log:1
./jvm1.128.log:2

How do I modify the command to get the unique exception count?

java.util.concurrent.ExecutionException : 1
java.lang.IllegalArgumentException : 1
java.lang.RuntimeException  : 2

Advertisement

Answer

you can use awk to get fifth column then sort and uniq -c will do the work

find . -name "*jvm*"|xargs grep " 000 "  | awk '{ print $5 }' | sort | uniq -c
Advertisement