Home | History | Annotate | Line # | Download | only in misc
make.country revision 1.1
      1 #!/bin/sh
      2 
      3 hdr() {
      4 echo '#' '$'NetBSD'$'
      5 cat << _EOF
      6 #
      7 # ISO 3166-1 Country Codes
      8 #
      9 # The format of an entry is:
     10 # <Name><TAB><Alpha-2-code><TAB><Alpha-3-code><TAB><Numeric-3-code><TAB><FIPS>
     11 #
     12 # Further information can be found at the ISO 3166 Maintenance Agency
     13 # (ISO 3166/MA) web site,
     14 # <http://www.iso.org/iso/en/prods-services/iso3166ma/index.html>.
     15 #
     16 # FIPS 10-4 codes compiled from several sources, including
     17 # http://www.statoids.com/wab.html
     18 #
     19 # ISO 3166-1 entities without exactly one corresponding FIPS code have a
     20 # blank entry in the column. FIPS 10-4 codes without a corresponding
     21 # ISO 3166-1 entity are excluded.
     22 #
     23 # This list is up-to-date as of $(date +%Y-%m-%d)
     24 #
     25 _EOF
     26 }
     27 
     28 I1=http://www.statoids.com/wab.html
     29 O1=/tmp/wab.$$
     30 I2=http://www.iso.org/iso/list-en1-semic-3.txt
     31 O2=/tmp/list.$$
     32 trap "rm -f wab.html list-en1-semic-3.txt $O1 $O2" 0 1 2 3 15
     33 ftp $I1
     34 ftp $I2
     35 
     36 grep '<tr class="[oe]">' wab.html |
     37 sed -e 's,<tr class="."><td>,,g' \
     38     -e 's,\&nbsp;,,g' \
     39     -e 's,<code>,,g' \
     40     -e 's,</code>,,g' \
     41     -e 's,<br>, ,g' \
     42     -e 's,</td><td>,	,g' \
     43     -e 's,,Aa,g' \
     44     -e 's,,o,g' \
     45     -e 's,</td></tr>,,g' |
     46 awk -F'\t' '{ printf("%s\t%s\t%s\t%s\t%s\n", $2, $3, $4, $6, $1); }' |
     47 grep -v href= |
     48 sort > $O1
     49 
     50 grep ';[A-Z][A-Z]' list-en1-semic-3.txt |
     51 tr -d '\015' |
     52 awk -F ';' '{ print $2 }' |
     53 sort > $O2
     54 
     55 hdr
     56 join -t '	' -o 1.5,1.1,1.2,1.3,1.4 -1 1 -2 1 $O1 $O2 | sort
     57