Common combination : Sort+uniq+head+awk
function analysis
Awk is very suitable for fetching columns and supports regular
Uniq calculates the number of occurrences of the column value that awk just fetched and goes back
Sort the number of occurrences of the uniq, which is sorted by the frequency of occurrence.
Head can be displayed by taking the first n rows
Processing Example: Remove the 3 most frequently occurring IPs in the following IP
[email protected] ~]# cat 123192.168.1.1192.168.1.2192.168.1.3192.168.1.4192.168.1.5192.168.1.5192.168.1.5192.168.1.10192.168.1.20192.168.1.30192.1 68.1.40192.168.1.50192.168.1.60192.168.1.70192.168.1.1192.168.1.3192.168.1.4192.168.1.1192.168.1.2
First-time Processing:
[Email protected] ~]# Sort 123 # #第一次处理后, the same values appear together 192.168.1.1192.168.1.1192.168.1.1192.168.1.10192.168.1.2192.168 .1.2192.168.1.20192.168.1.3192.168.1.3192.168.1.30192.168.1.4192.168.1.4192.168.1.40192.168.1.5192.168.1.5192.168.1.5192. 168.1.50192.168.1.60192.168.1.70
Second treatment:
[Email protected] ~]# sort 123|uniq-c# #第二次处理出现了出现次数的记录3 192.168.1.11 192.168.1.102 192.168.1.21 192.168.1.202 192.168. 1.31 192.168.1.302 192.168.1.41 192.168.1.403 192.168.1.51 192.168.1.501 192.168.1.601 192.168.1.70
Third-time Processing:
[[email protected] ~]# sort 123|uniq-c|sort-r# #第三次处理, descending order of occurrences 3 192.168.1.53 192.168.1.12 192.168.1.42 192.168.1.32 192 .168.1.21 192.168.1.701 192.168.1.601 192.168.1.501 192.168.1.401 192.168.1.301 192.168.1.201 192.168.1.10
Fourth-time Processing:
[Email protected] ~]# sort 123|uniq-c|sort-r|head-n 3# #取出前三个3 192.168.1.53 192.168.1.12 192.168.1.4
The real difficulty in sorting is the value of awk, how to take out all the IP specifications
The options for sort can refer to http://www.cnblogs.com/ningvsban/p/3724306.html
Sort how to order, how to take IP according to the number of occurrences