Statitics to all contries

This commit is contained in:
Arkadiusz Hypki 2023-05-15 18:40:38 +02:00
parent d7c3c77ef7
commit c0671db3bb

View File

@ -8,12 +8,11 @@ echo "Podaj plik z danymi"
read inPlik read inPlik
echo "Podaj wiek" echo "Podaj wiek"
read inWiek read inWiek
echo "Podaj kraj"
read inKraj
ile=0
wszyscy=0 wszyscy=0
declare -A kraje
# iterating line-by-line # iterating line-by-line
while read line while read line
do do
@ -27,9 +26,9 @@ then
wszyscy=$((wszyscy+1)) wszyscy=$((wszyscy+1))
if [ $country = "$inKraj" -a $age -ge $inWiek ] if [ $age -ge $inWiek ]
then then
ile=$((ile+1)) kraje["$country"]=$((kraje["$country"]+1))
echo "Person $name (from $country) is $age years old" echo "Person $name (from $country) is $age years old"
fi fi
@ -38,4 +37,9 @@ fi
done < $inPlik done < $inPlik
#echo "There is $ile people from $inKraj (from all $wszyscy people)" #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