Rajesh
Rajesh

Reputation: 27

need to write shell script for match word from log file

i have a log file as..

>java.lang.IllegalStateException: Unable to crypt bytes with cipher [javax.crypto.Cipher@61e02bf7].
>Caused by: javax.crypto.IllegalBlockSizeException: Input length must be multiple of 8 when decrypting with padded cipher
>org.apache.solr.client.solrj.SolrServerException: Error executing query
>org.apache.jasper.JasperException: javax.servlet.ServletException: >net.sourceforge.stripes.exception.StripesJspException: An exception was raised while invoking
>Caused by: javax.servlet.ServletException: net.sourceforge.stripes.exception.StripesJspException: An exception was raised while invoking a layout. The layout used w
>Caused by: org.apache.jasper.JasperException: java.util.ConcurrentModificationException
>java.lang.NumberFormatException: empty String
>com.hk.exception.DefaultWebException: Order Total cannot be lesser than 0
>java.lang.NumberFormatException: For input string: ".E0"

i need a result only those word which end with "Exception:" and no of times word repeating.. eg like..

IllegalStateException   1
IllegalBlockSizeException  1
SolrServerException  1
JasperException  2
ServletException  2
NumberFormatException  2
DefaultWebException  1

Please help ....

Upvotes: 0

Views: 384

Answers (3)

user184968
user184968

Reputation:

awk '{ for(i=1;i<=NF;++i) if (match($i,"Exception")!=0) {arr[gensub(/.*\.([a-zA-Z]*Exception[a-zA-Z]*).*/,"\\1","", $i)]++;} } END { for(v in arr) {print v, arr[v];} }' log

This is how it works:

>awk '{ for(i=1;i<=NF;++i) if (match($i,"Exception")!=0) {arr[gensub(/.*\.([a-zA-Z]*Exception[a-zA-Z]*).*/,"\\1","", $i)]++;} } END { for(v in arr) {print v, arr[v];} }' log
ServletException 2
JasperException 2
ConcurrentModificationException 1
DefaultWebException 1
NumberFormatException 2
StripesJspException 2
IllegalStateException 1
SolrServerException 1
IllegalBlockSizeException 1

Upvotes: 0

Ray Toal
Ray Toal

Reputation: 88378

If that piece of the log file you posted were put into a file called log, then try this:

egrep -o '\<\w+Exception\>' log | sort | uniq -c

Which would give you:

  1 ConcurrentModificationException
  1 DefaultWebException
  1 IllegalBlockSizeException
  1 IllegalStateException
  2 JasperException
  2 NumberFormatException
  2 ServletException
  1 SolrServerException
  2 StripesJspException

Upvotes: 2

Mukund K Roy
Mukund K Roy

Reputation: 165

Or You simply can use

grep "<your search key word>" <log-file-name> redirect output to a file if you want.

There are several options also with grep command.

Upvotes: 0

Related Questions