From d7c3c77ef72bf83d1cd5673f9745bbca595bf0f3 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 15 May 2023 18:05:39 +0200 Subject: [PATCH] Computing statistics with percent how many people comes from a given country --- tabledata/ex1.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tabledata/ex1.sh b/tabledata/ex1.sh index 2b562c6..05ec7bc 100755 --- a/tabledata/ex1.sh +++ b/tabledata/ex1.sh @@ -11,6 +11,8 @@ read inWiek echo "Podaj kraj" read inKraj +ile=0 +wszyscy=0 # iterating line-by-line while read line @@ -23,11 +25,17 @@ country=`echo $line | cut -d " " -f 3` if [ $name != "#" ] then +wszyscy=$((wszyscy+1)) + if [ $country = "$inKraj" -a $age -ge $inWiek ] then + ile=$((ile+1)) echo "Person $name (from $country) is $age years old" fi 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"