2012-12-14 136 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