diff options
author | Marcus Glocker <mglocker@cvs.openbsd.org> | 2024-08-23 15:23:00 +0000 |
---|---|---|
committer | Marcus Glocker <mglocker@cvs.openbsd.org> | 2024-08-23 15:23:00 +0000 |
commit | b5edcd5fcf5b68334f1ab4cf8e1f6931f467bab7 (patch) | |
tree | f8744ba8cbd2863c30e0405aed9286556dc5425f /games | |
parent | e3533357afa2c60664d1af98f3b89e6bc15b3ab4 (diff) |
Speed up script by using awk(1).
Discussed with deraadt@
Diffstat (limited to 'games')
-rwxr-xr-x | games/quiz/naphone2areas.sh | 40 |
1 files changed, 13 insertions, 27 deletions
diff --git a/games/quiz/naphone2areas.sh b/games/quiz/naphone2areas.sh index febfa3fbf64..aac47d3eef3 100755 --- a/games/quiz/naphone2areas.sh +++ b/games/quiz/naphone2areas.sh @@ -10,30 +10,16 @@ if [ X"$1" == X"" ]; then exit 1 fi -AC=0 -grep -v '\#' $1 | grep -v '\$' | \ -while T= read -r line; do - AC_LAST=$AC - AC=`echo $line | cut -d: -f1` - - # skip line if area code isn't numeric - CMD=`echo $AC | grep "^[0-9]*$"` - if [ $? -eq 1 ]; then - continue - fi - - # skip line if area code is a duplicate - if [ $AC -eq $AC_LAST ]; then - continue - fi - - C=`echo $line | cut -d: -f2` - SP=`echo $line | cut -d: -f3` - SPA=`echo $line | cut -d: -f4` - - if [ X"$SPA" == X"" ]; then - echo "$AC:$SP:$C" - else - echo "$AC:$SP|$SPA:$C" - fi -done +awk '{ + split($0, a, ":"); + + if (a[1] ~ /^[0-9]+$/) { + if (last != a[1]) { + if (a[4] == "") + print a[1] ":" a[3] ":" a[2]; + else + print a[1] ":" a[3] "|" a[4] ":" a[2]; + } + } + last = a[1]; +}' $1 |