The linux Command counts the number of times the IP address of the log file appears.

Source: Internet
Author: User

The linux Command counts the number of times the IP address of the log file appears.

One interview question:

How many times does the log file IP value count? The first six most frequently displayed

Solution:

Grep-I-o-E "([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "test1.txt | sort-n | uniq-c | sort-n? -R | head-6

Parameter Details:

Grep command for text search

-E: used for regular expression matching.

-O: only the matching part is displayed.

-I: case insensitive

The sort command is used for sorting

-N: Numerical sorting

-R: reverse sorting

Uniq command for deduplication

-C: displays the number of duplicates.

The head-6 command displays the first six lines

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.