A solution to the contents of the statistics sort in Linux containing blank lines

Source: Internet
Author: User

A solution to the contents of the statistics sort in Linux containing blank lines

Nonsense not much to say, directly on the example:

The contents of the file Sharkyun.log are as follows

[Email protected] ~]# cat-n Sharkyun.log

1http://www.sharkyun.com/index.html

2http://www.sharkyun.com/index.shtml

3https://post.sharkyun.com/index.html

4https://mp3.sharkyun.com/index.html

5http://www.sharkyun.com/index.jsp

6http://post.sharkyun.com/99.html

7

Note: There are spaces in line seventh!

I don't think you're going to want the following statistic results.

[[email protected] ~]# awk-f/' {print $} ' Sharkyun.log |sort |uniq-c

1

1 mp3.sharkyun.com

2 post.sharkyun.com

3 www.sharkyun.com

[Email protected] ~]#


So, you should.

[[email protected] ~]# awk-f/' nf>1{print $} ' sharkyun.log |sort |uniq-c

1 mp3.sharkyun.com

2 post.sharkyun.com

3 www.sharkyun.com

[Email protected] ~]#

Option Description:

Nf>1 ====> indicates that to conform, when a slash delimiter is divided, the number of fields to be split is greater than 1, and awk processes the print line;

The empty line will naturally not be processed.


Or so.

[Email protected] ~]# cut-d "/"-sf3 Sharkyun.log |sort |uniq-c

1 mp3.sharkyun.com

2 post.sharkyun.com

3 www.sharkyun.com

[Email protected] ~]#

Option Description:

-D ===> Specifies that the slash is the delimiter for the delimited field

-S ===> to not print lines that do not contain a delimiter

The-f ===> indicates the number of fields (here is the 3rd) after the delimiter defined with-D in print (output)


Maybe the boss will let you make a big-to-small ranking.

[Email protected] ~]# cut-d "/"-sf3 Sharkyun.log |sort |uniq-c|sort-rn

3 www.sharkyun.com

2 post.sharkyun.com

1 mp3.sharkyun.com

[Email protected] ~]#


This article is from the Linux OPS architect blog, so be sure to keep this source http://sharkyun.blog.51cto.com/10455795/1789852

A solution to the contents of the statistics sort in Linux containing blank 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.