2012-12-14 93 views
0

編寫shell腳本,匹配詞我有一個日誌文件..需要從日誌文件中

>java.lang.IllegalStateException: Unable to crypt bytes with cipher [[email protected]]. 
>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" 

我需要的結果只有那些字到底該用「異常:」沒有時間詞的重複。 。 例如像..

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

請幫助....

回答

2

如果你發佈的那件日誌文件被放入一個所謂的日誌文件,然後試試這個:

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

這將使你:

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

,或者你只是可以使用

grep "<your search key word>" <log-file-name>輸出重定向到一個文件,如果你想要的。

grep命令還有幾個選項。

0
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 

這是它如何工作的:

>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