脚本列出所有的例外情况及其发生的数 [英] A script to list all the exceptions and their number of occurrence

查看:144
本文介绍了脚本列出所有的例外情况及其发生的数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有codeD可以分析一个文件,并返回不同结果的分析: GOOD BAD 意外异常:后面是不同的异常...我的生成文件运行此分析仪上的一组文件之一接着一个,并把整个结果在一个文件中 output.txt的。因此, output.txt的看起来如下:

I have coded an analyzer which analyzes a file, and returns different results: GOOD, BAD, Unexpected exception : which is followed by different exceptions... My makefile runs this analyzer on a set of files one by one, and puts the whole result in one file output.txt. So the output.txt looks like as follows:

file "f1.txt"
...
GOOD
file "f2.txt"
...
Unexpected exception : exception1
...
Unexpected exception : exception2
...

现在我想编写一个shell脚本摘要,总结 output.txt的,尤其是名单是什么例外凸起和它们发生的次数。它应该喜欢就好:

Now I would like to write a shell script summary which summarizes output.txt, especially lists what exceptions are raised and their number of occurrence. It should like like:

exception1 : 9
exception2 : 15
...

例外的顺序没有任何意义,(当然,如果是发生数进行排序,这将是更好的)...

The order of the exceptions has no importance, (well, if it is sorted by the number of the occurrence, it would be better)...

我知道 grep的意外的异常output.txt的|厕所-l 将返回所有的异常出现的次数,但我确实需要知道募集每个异常的发生...

I know grep "Unexpected exception" output.txt | wc -l will return the number of occurrence of all the exceptions, but I do need to know the occurrence for each exception raised...

有谁知道如何写这个摘要脚本?

Does anyone know how to write this summary script?

推荐答案

您可以用awk:

awk -F ' : ' '$1=="Unexpected exception"{a[$2]++} END{for (i in a) print i,a[i]}' output.txt

这篇关于脚本列出所有的例外情况及其发生的数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆