From: mglocker Date: Fri, 23 Aug 2024 15:22:59 +0000 (+0000) Subject: Speed up script by using awk(1). X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=106a53474636c19a579f099b18d7b440a05e1950;p=openbsd Speed up script by using awk(1). Discussed with deraadt@ --- 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