transferred from: http://blog.csdn.net/guaguastd/article/details/8332757use the Shell to count the number of occurrences Top10 URLsCategory: Shell scripts 2012-12-19 17:17 286 people read reviews (0) favorite reports Ranking of statistics
[Plain]View Plaincopy
- #!/bin/sh
- Foo ()
- {
- If [$#-ne 1];
- Then
- echo "usage:$0 filename";
- Exit-1
- Fi
- Egrep-o "http://[a-za-z0-9." +\. [A-za-z] {2,3} "website | awk ' {count[$0]++} END {printf ("%-30s%s\n", "Wensite", "Count"), for (Ind in count) {printf ("%-30s%d\n", Ind,count[ind]) ; }} ' | SORT-NRK 2 | Head-n >websorted2.txt;
- }
- Foo website
Example:
Content in file website:
http://www.google.com
http://www.baidu.com
http://www.sina.com
http://www.bjtu.edu.cn
/http www.codeproject.com
http://www.csdn.com
http://www.sohu.com
http://www.yahoo.com
/http mail.163.com
http://www.bjtu.edu.cn
http://www.codeproject.com
http://www.csdn.com
/http www.sohu.com
http://www.yahoo.com
http://mail.163.com
http://www.codeproject.com
/http www.csdn.com
http://www.sohu.com
http://www.yahoo.com
http://mail.163.com
http://www.qq.com
http://www.hao123.com
http://www.163.com
http://youku.com
http://taobao/com
http://www.bjtu.edu.cn
http://www.codeproject.com
http://www.csdn.com
http://www.sohu.com
http://www.yahoo.com
http:/ /mail.163.com
http://www.codeproject.com
http://www.csdn.com
http://www.sohu.com
/http www.yahoo.com
http://mail.163.com
http://www.qq.com
http://www.hao123.com
http://www.163.com
Http://youku.com
Http://taobao/com
The resulting file content is (that is, the result)
Http://www.yahoo.com 5
Http://www.sohu.com 5
Http://www.csdn.com 5
Http://www.codeproject.com 5
Http://mail.163.com 5
Http://www.bjtu.edu.cn 3
Http://youku.com 2
Http://www.qq.com 2
Http://www.hao123.com 2
Http://www.163.com 2
Use the shell to count the number of occurrences of the Top10 URL (not found in the blog Park, special Turn)