wikipedia-number-names.sh 865 B

123456789101112131415161718192021222324252627
  1. #!/bin/sh
  2. # Parse the table located at
  3. # https://en.wikipedia.org/wiki/List_of_notable_numbers#English_names_for_powers_of_10
  4. # to generate commands to build table in lua where the index is the power and
  5. # the value is the name
  6. last_power=
  7. echo "number_names = {}"
  8. curl -s https://en.wikipedia.org/wiki/List_of_notable_numbers | \
  9. sed -n "/English names for powers of 10/,/Proposed systematic names for powers of 10/p" | \
  10. grep sup.*sup -A 1 | \
  11. while read line
  12. do
  13. power=$(awk -v FS="(<sup>|</sup>)" '{print $2}' <<< "$line")
  14. if ! [ -z "$power" ]; then
  15. last_power="$power"
  16. fi
  17. name=$(awk -v FS="(<td>|</td>)" '{print $2}' <<< "$line")
  18. if ! [ -z "$last_power" ] && \
  19. ! [ -z "$name" ] && \
  20. [ "$(tr -cd [:alpha:] <<< "$name")" = "$name" ]
  21. then
  22. echo "number_names[$last_power] = \"$name\""
  23. fi
  24. done