Use cat to count apache log ip addresses

Source: Internet
Author: User
Tags apache log
To use cat to count the ip address of an apache log, extract the IP address with the highest access volume from the log. Use shell. Www.2cto.com logs are as follows (for example, the data volume is small): $moreaa.txt 127.0.0.1-frank [10/Oct/2000: 13 :... to use cat to count the ip address of an apache log, extract the IP address with the highest access volume from the log. Use shell. Www.2cto.com logs are as follows (for example, the data volume is small): $ more aa.txt 127.0.0.1-frank [10/Oct/2000: 13: 55: 36-0700] "GET/apache_pb.gif HTTP/1.0" 200 2326 192.168.1.100-frank [10/Oct/2000: 13: 55: 36-0700] "GET/apache_pb.gif HTTP/1.0" 200 2326 192.168.1.100-frank [10/Oct/2000: 13: 55: 36-0700] "GET/apache_pb.gif HTTP/1.0" 200 2326 192.168.1.100-frank [10/Oct/2000: 13: 55: 36-0700] "GET/apache_pb.gif HTTP/1.0" 200 232 6. to extract the IP address with the highest access volume, extract the IP address segment from the log. $ Cat aa.txt | awk-F "" '{print $1}' 127.0.0.1 192.168.1.100 192.168.1.100 192.168.1.100 (PS, which can also be implemented using the cut command here. $ Cut-d ""-f 1 aa.txt 127.0.0.1 192.168.1.100 192.168.1.100 192.168.1.100) 2. check the IP address statistics to see how many times each IP address has appeared $ cat aa.txt | awk-F "" '{print $1}' | uniq-c 1 127.0.0.1 3 192.168.1.100 (PS: wc-l can also calculate the number of rows, but the statistics are the total number of all rows. Does not classify statistics) 3. sort by IP addresses in ascending order $ cat aa.txt | awk-F "" '{print $1}' | uniq-c | sort-r 3 192.168.1.100 1 127.0.0.1 4. extract the IP address segment $ cat aa.txt again | awk-F "" '{print $1}' | uniq-c | sort-r | awk '{print $2}' 192.168.1.100 127.0.0.1 5. select the first line $ cat aa.txt | awk-F "" '{print $1}' | uniq-c | sort-r | awk '{print $2}' | head- 1 192.168.1.100
Related Article

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.