From de44f3ece74ce91a9fbdbd5c544393e7f76d7fca Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 15 May 2023 16:44:42 +0200 Subject: [PATCH] ex1.sh changed to compute statistical occurences of given person from a given country --- tabledata/ex1.sh | 8 ++++++++ tabledata/people | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/tabledata/ex1.sh b/tabledata/ex1.sh index 5d99cb6..9d8d693 100755 --- a/tabledata/ex1.sh +++ b/tabledata/ex1.sh @@ -11,6 +11,9 @@ read inKraj echo "Podaj minimalny wiek" read inWiek +w=0 +sz=0 + # iterating line-by-line while read line do @@ -22,11 +25,16 @@ country=`echo $line | cut -d " " -f 3` if [ $name != "#" ] then +w=$((w + 1)) + if [ $country = "$inKraj" -a $age -ge $inWiek ] then + sz=$((sz + 1)) echo "Person $name (from $country) is $age years old" fi fi done < $inPlikWej + +echo "There is statistically `echo "scale=2; $sz/$w*100.0" | bc -l` % of such persons" diff --git a/tabledata/people b/tabledata/people index b9aca01..61020d9 100644 --- a/tabledata/people +++ b/tabledata/people @@ -1,8 +1,13 @@ # name age country Peter 45 Poland Christof 34 Germany +Jurgen 24 Germany Paul 35 Poland Jacek 55 Poland +Jurek 67 Poland Maria 23 France Jerry 25 Germany Paul 60 France +Frederic 9 France +Agostino 20 Italy +Toni 15 Italy