From c0671db3bb6d026b4c50f5c83d27cd8517feff00 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 15 May 2023 18:40:38 +0200 Subject: [PATCH] Statitics to all contries --- tabledata/ex1.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/tabledata/ex1.sh b/tabledata/ex1.sh index 05ec7bc..ccc0513 100755 --- a/tabledata/ex1.sh +++ b/tabledata/ex1.sh @@ -8,12 +8,11 @@ echo "Podaj plik z danymi" read inPlik echo "Podaj wiek" read inWiek -echo "Podaj kraj" -read inKraj -ile=0 wszyscy=0 +declare -A kraje + # iterating line-by-line while read line do @@ -27,9 +26,9 @@ then wszyscy=$((wszyscy+1)) -if [ $country = "$inKraj" -a $age -ge $inWiek ] +if [ $age -ge $inWiek ] then - ile=$((ile+1)) + kraje["$country"]=$((kraje["$country"]+1)) echo "Person $name (from $country) is $age years old" fi @@ -38,4 +37,9 @@ fi done < $inPlik #echo "There is $ile people from $inKraj (from all $wszyscy people)" -echo "There is `echo "scale=2; $ile/$wszyscy*100.0" | bc -l`% people from $inKraj" +#echo "There is `echo "scale=2; $ile/$wszyscy*100.0" | bc -l`% people from $inKraj" +#echo "Num of people from Poland is ${kraje["Poland"]}" +#echo "Num of people from Germany is ${kraje["Germany"]}" + + +for key in ${!kraje[@]}; do echo "People from $key is `echo "scale=2; ${kraje["$key"]}/$wszyscy*100.0" | bc -l`%"; done