SHELL日志分析 实例一

要求:

将该文件中的域名截取出来,统计重复域名出现的次数,然后按次数进行降序排列

[root@tyzZ SHELL]# cat file 
http://www.linuxidc.com/index.html
http://www.google.com/index.html
http://www.linuxidc.com/get.html
http://www.linuxidc.com/set.html
http://www.google.com/index.html
http://www.yahoo.com.cn/put.html

第一步 先截取域名

[root@tyzZ SHELL]# awk -F"/" '{print $3}' file
www.linuxidc.com
www.google.com
www.linuxidc.com
www.linuxidc.com
www.google.com
www.yahoo.com.cn

第二步 排序

[root@tyzZ SHELL]# awk -F"/" '{print $3}' file |sort
www.google.com
www.google.com
www.linuxidc.com
www.linuxidc.com
www.linuxidc.com
www.yahoo.com.cn
[root@tyzZ SHELL]# awk -F"/" '{print $3}' file |sort|uniq -c
      2 www.google.com
      3 www.linuxidc.com
      1 www.yahoo.com.cn
[root@tyzZ SHELL]# awk -F"/" '{print $3}' file |sort|uniq -c|sort -frn
      3 www.linuxidc.com
      2 www.google.com
      1 www.yahoo.com.cn