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