Use the shell to count the number of occurrences of the Top10 URL (not found in the blog Park, special Turn)

Source: Internet
Author: User

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
  1. #!/bin/sh
  2. Foo ()
  3. {
  4. If [$#-ne 1];
  5. Then
  6. echo "usage:$0 filename";
  7. Exit-1
  8. Fi
  9. 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;
  10. }
  11. 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)

Related Article

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.