Sort how to order, how to take IP according to the number of occurrences

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.