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.
- #! /Usr/bin/bash
- ######################################## ########################################
- # Program: script program for getting points from five major league teams
- #
- # Author: hailongchang@163.com
- #
- # Date: 2008/11/17
- ######################################## ########################################
- Function usage (){
- Echo
"Select the League ranking you want to view :"
- Echo
- Echo
"1 England Super League"
- Echo
"2 Italian soccer league"
- Echo
"3 German soccer league"
- Echo
"4 Spanish soccer league"
- Echo
"5 French soccer league"
- Echo
- Read-P
"Select serial number :"
Choice
- Case
$ Choice in
- "1"
)
- Name =
"EPL"
- ;;
- "2"
)
- Name =
"Seri"
- ;;
- "3"
)
- Name =
"Bund"
- ;;
- "4"
)
- Name =
"Liga"
- ;;
- "5"
)
- Name =
"Fran"
- ;;
- *)
- Usage
- ;;
- Esac
- }
- Usage
- Database =
"Http://stats.sports.sohu.com/istanding.aspx? Lega ="
- If
[-N $ name]; then
- Address = $ database $ {name}
- Fi
- Curl $ address 2>/dev/null |
- Sed-e'
- S/<[//] * HTML>
// G;
- S/<[//] * body>
// G;
- S/<[//] * script [^>] *>
// G;
- S/<[//] * Table [^>] *>
// G;
- S/<[//] * Div [^>] *>
// G;
- S/<[//] * Form [^>] *>
// G;
- S/<[//] * TD [^>] *>
// G;
- S/<[//] * tr [^>] *>
// G;
- S/<[//] * A [^>] *>
// G;
- S/. * [; {}>] $
// G;
- '| Sed-e'
S/[/T] *
// G; S/[0-9]/{1, 4/}-[0-9]/{1, 4 /}. * // G;/^ $/d' | sed-e'
- 1i ################################
- 11i ################################
- 21i ################################
- 31i ################################
- 41i ################################
- 51i ################################
- 61i ################################
- 71i ################################
- 81i ################################
- 91i ################################
- 101i ################################
- 111i ################################
- 121i ################################
- 131I ################################
- 141i ################################
- 151i ################################
- 161i ################################
- 171i ################################
- 181i ################################
- 191i ################################
- 201i ################################
- 211i ################################
- 221i ################################
- 231i ################################
- '| Awk'
- Begin {
- Rs =
"################################/N"
- FS =
"/N"
- # OFS = "/t"
- }
- {
- 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)
- }'