From b5edcd5fcf5b68334f1ab4cf8e1f6931f467bab7 Mon Sep 17 00:00:00 2001 From: Marcus Glocker Date: Fri, 23 Aug 2024 15:23:00 +0000 Subject: Speed up script by using awk(1). Discussed with deraadt@ --- games/quiz/naphone2areas.sh | 40 +++++++++++++--------------------------- 1 file changed, 13 insertions(+), 27 deletions(-) (limited to 'games') 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 -- cgit v1.2.3