Top access log statistics by ip Address

Source: Internet
Author: User
Command 1: Shell code timeawk {print $1} access. log | sort | uniq-c | sort-nr | head-578129192.168.13.16675165192.168.12.5258657192.168.12.19954146192.168.13.18334310192.168.13.181real0m5.849suser0m5.566ssys0m0.285s command 2

Command 1: Shell code time awk '{print $1}' access. log | sort | uniq-c | sort-nr | head-5 78129 192.168.13.166 75165 192.168.12.52 58657 192.168.12.199 54146 192.168.13.183 34310 192.168.13.181 real 0m5. 849 s user 0m5. 566 s sys 0m0. 285 s command 2

Command 1:

Shell code

Time awk '{print $1}' access. log | sort | uniq-c | sort-nr | head-5

78129 192.168.13.166

75165 192.168.12.52

58657 192.168.12.199

54146 192.168.13.183

34310 192.168.13.181

Real 0m5. 849 s

User 0m5. 566 s

Sys 0m0. 285 s

Command 2:

Shell code

Time awk '{a [$1] ++} END {for (I in a) {printf ("% d \ t % s \ n", a [I], i)} 'access. log | sort-nr | head-5

78129 192.168.13.166

75165 192.168.12.52

58657 192.168.12.199

54146 192.168.13.183

34310 192.168.13.181

Real 0m0. 626 s

User 0m0. 549 s

Sys 0m0. 080 s

The preceding twoStatisticsTop Command, the comparison result is clear at a glance. Command 1 is convenient and efficient; command 2 is troublesome and efficient.

The reason why I thought of comparing these two commands was due to an interview. At that time, my answer was command 2 (I used to use command 2 before that, but I did not use command 1 ). The other party immediately questioned the answer I gave. First, I doubt the correctness of the answer. "Isn't this method correct ?". When I explained that I have used this command in my work, I questioned the efficiency of this command. "There should be more efficient methods !".

What I actually want to say is that sometimes the interview may not be able to identify the real problem.

[Editor: peter]

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.