如何排序,uniq的和显示行比X次出现比较 [英] How to sort,uniq and display line that appear more than X times

查看:144
本文介绍了如何排序,uniq的和显示行比X次出现比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的文件:

  80.13.178.2
80.13.178.2
80.13.178.2
80.13.178.2
80.13.178.1
80.13.178.3
80.13.178.3
80.13.178.3
80.13.178.4
80.13.178.4
80.13.178.7

我需要重复线显示唯一条目(类似于uniq的-d),但只有条目中发生的的不仅仅是两次(即两次实例以便灵活地定义的下限。)

在这个例子中的输出应该是这样的寻找具有三个或更多的事件条目时:

  80.13.178.2
80.13.178.3


解决方案

通过纯 AWK

 的awk'{a [$ 0] ++} END {为(我的){如果(A [I]> 2){打印I}}}'一个。文本

它遍历文件,并计算每个IP的occurances。在该文件的末尾其输出发生的2倍以上的每个IP

I have a file like this:

80.13.178.2
80.13.178.2
80.13.178.2
80.13.178.2
80.13.178.1
80.13.178.3
80.13.178.3
80.13.178.3
80.13.178.4
80.13.178.4
80.13.178.7

I need to display unique entries for repeated line (similar to uniq -d) but only entries that occur more than just twice (twice being an example so flexibility to define the lower limit.)

Output for this example should be like this when looking for entries with three or more occurrences:

80.13.178.2
80.13.178.3

解决方案

With pure awk:

awk '{a[$0]++}END{for(i in a){if(a[i] > 2){print i}}}' a.txt 

It iterates over the file and counts the occurances of every IP. At the end of the file it outputs every IP which occurs more than 2 times.

这篇关于如何排序,uniq的和显示行比X次出现比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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