如何使用以下访问日志获取uniq报告

时间:2015-05-26 09:25:43

标签: awk sed grep cut

输入

Severity: Warning   Missing argument 1 for Pxxer_rzxczt_v3::mast() /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 115/dadm/index.php/plasdasd/mast/  
Severity: Warning   Missing argument 1 for Pxxer_rzxczt_v3::mast() /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 115/dadm/index.php/plasdasd/mast/  
Severity: Warning   Missing argument 1 for Pxxer_rzxczt_v3::mast() /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 115/dadm/index.php/plasdasd/mast/  
Severity: Notice   Undefined variable: vedwe erwer rew  /sdfdsfv/ddw/hdd/nddd/system/adsdn/wefwf/efe/codsds/pr_rt_v3.php 130/dadm/index.php/plasdasd/mast/  
Severity: Notice   Undefined variable: vedwe erwer rew  /sdfdsfv/ddw/hdd/nddd/system/adsdn/wefwf/efe/codsds/pr_rt_v3.php 130/dadm/index.php/plasdasd/mast/  
Severity: Notice   Undefined variable: vCode /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 130/dadm/index.php/plasdasd/mast/  
Severity: Notice   Undefined variable: vCode /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 130/dadm/index.php/plasdasd/mast/  
Severity: Notice   Undefined variable: vCode /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 130/dadm/index.php/plasdasd/mast/  

输出

Severity: Warning   Missing argument 1 for Pxxer_rzxczt_v3::mast() /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 115  - 3  
Severity: Notice   Undefined variable: vCode /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 130   -  3   
Severity: Notice   Undefined variable: vedwe erwer rew  /sdfdsfv/ddw/hdd/nddd/system/adsdn/wefwf/efe/codsds/pr_rt_v3.php 130   -  2  

1 个答案:

答案 0 :(得分:0)

uniq unix命令可以使用-c选项执行所需操作。

cat yourlog | uniq -c将输出

   1 everity: Warning   Missing argument 1 for Pxxer_rzxczt_v3::mast() /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 115/dadm/index.php/plasdasd/mast/  
   2 Severity: Warning   Missing argument 1 for Pxxer_rzxczt_v3::mast() /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 115/dadm/index.php/plasdasd/mast/  
   2 Severity: Notice   Undefined variable: vedwe erwer rew  /sdfdsfv/ddw/hdd/nddd/system/adsdn/wefwf/efe/codsds/pr_rt_v3.php 130/dadm/index.php/plasdasd/mast/  
   3 Severity: Notice   Undefined variable: vCode /sdfdsfv/ddw/hdd/nddd/system/adsdn/codsds/pr_rt_v3.php 130/dadm/index.php/plasdasd/mast/  

然而,这将使得在彼此之后不直接重复的重复行在不同的行上计数。

例如输入:

foo
foo
bar
bar
foo
foo

将给出输出:

2 foo
2 bar
2 foo

如果您想要输出

2 bar
4 foo

首先必须对文件进行排序,如下所示:

cat yourlog | sort | uniq -c