Use shell script to view the five League points

Source: Internet
Author: User
Tags network function

At ordinary times, I seldom have time and energy to watch the live broadcast of the five major league matches. But I still pay close attention to the progress of the competition. However, I have to check the information online and have a lot of links, last week I wrote a program using awk to download YouTube videos. This time I still want to use the network function provided by gawk to complete such a program, but I encountered a lot of difficulties, for example, I need to obtain the ranking information in the begin process and use regular expressions to filter the page multiple times. The combination of SED and awk is used to complete this work. In addition, curl is used to obtain the webpage, which is much easier than the HTTP header analysis method in gawk, the program runs in cygwin as follows:

 

 


 

The following is the code. It is not difficult to explain the regular expression. In order to distinguish rs in awk, sed is specially used to add a line '#' between records. This is not an exquisite place. If this is not the case, RS is set to a blank line, if the FS is set as a line break, it cannot get good results. Maybe the regular expressions in RS and fs are not well written. If you are interested, we can exchange ideas.

 

  1. #! /Usr/bin/bash
  2. ######################################## ########################################
  3. # Program: script program for getting points from five major league teams
  4. #
  5. # Author: hailongchang@163.com
  6. #
  7. # Date: 2008/11/17
  8. ######################################## ########################################
  9. Function usage (){
  10. Echo
    "Select the League ranking you want to view :"
  11. Echo
  12. Echo
    "1 England Super League"
  13. Echo
    "2 Italian soccer league"
  14. Echo
    "3 German soccer league"
  15. Echo
    "4 Spanish soccer league"
  16. Echo
    "5 French soccer league"
  17. Echo
  18. Read-P
    "Select serial number :"
    Choice
  19. Case
    $ Choice in
  20. "1"
    )
  21. Name =
    "EPL"
  22. ;;
  23. "2"
    )
  24. Name =
    "Seri"
  25. ;;
  26. "3"
    )
  27. Name =
    "Bund"
  28. ;;
  29. "4"
    )
  30. Name =
    "Liga"
  31. ;;
  32. "5"
    )
  33. Name =
    "Fran"
  34. ;;
  35. *)
  36. Usage
  37. ;;
  38. Esac
  39. }
  40. Usage
  41. Database =
    "Http://stats.sports.sohu.com/istanding.aspx? Lega ="
  42. If
    [-N $ name]; then
  43. Address = $ database $ {name}
  44. Fi
  45. Curl $ address 2>/dev/null |
  46. Sed-e'
  47. S/<[//] * HTML>
    // G;
  48. S/<[//] * body>
    // G;
  49. S/<[//] * script [^>] *>
    // G;
  50. S/<[//] * Table [^>] *>
    // G;
  51. S/<[//] * Div [^>] *>
    // G;
  52. S/<[//] * Form [^>] *>
    // G;
  53. S/<[//] * TD [^>] *>
    // G;
  54. S/<[//] * tr [^>] *>
    // G;
  55. S/<[//] * A [^>] *>
    // G;
  56. S/. * [; {}>] $
    // G;
  57. '| Sed-e'
    S/[/T] *
    // G; S/[0-9]/{1, 4/}-[0-9]/{1, 4 /}. * // G;/^ $/d' | sed-e'
  58. 1i ################################
  59. 11i ################################
  60. 21i ################################
  61. 31i ################################
  62. 41i ################################
  63. 51i ################################
  64. 61i ################################
  65. 71i ################################
  66. 81i ################################
  67. 91i ################################
  68. 101i ################################
  69. 111i ################################
  70. 121i ################################
  71. 131I ################################
  72. 141i ################################
  73. 151i ################################
  74. 161i ################################
  75. 171i ################################
  76. 181i ################################
  77. 191i ################################
  78. 201i ################################
  79. 211i ################################
  80. 221i ################################
  81. 231i ################################
  82. '| Awk'
  83. Begin {
  84. Rs =
    "################################/N"
  85. FS =
    "/N"
  86. # OFS = "/t"
  87. }
  88. {
  89. Printf (
    "% 4 s/t % 10 s/t % 4 s/t % 4 s/t % 4 s/t % 4 s/t % 4 s/t % 4 s/t % 4 s/t % 4 s/t/N"
    , $1, $2, $3, $4, $5, $6, $7, $8, $9, $10)
  90. }'

 

 

 

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.