From 8c156a9981201279454a22fdbac8b556ad498b08 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 15 May 2023 17:06:50 +0200 Subject: [PATCH 1/4] Zaktualizuj 'tabledata/ex1.sh' --- tabledata/ex1.sh | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/tabledata/ex1.sh b/tabledata/ex1.sh index fb96f9f..04162d0 100755 --- a/tabledata/ex1.sh +++ b/tabledata/ex1.sh @@ -4,15 +4,6 @@ #numOfPeople=`cat $1 | grep $2 | wc -l` #echo "Num. of people from $2 is $numOfPeople" -echo "Podaj nazwę pliku z bazą danych" -read inPlikWej -echo "Podaj minimalny wiek" -read inWiek - -w=0 - -declare -A kraje - # iterating line-by-line while read line do @@ -24,16 +15,11 @@ country=`echo $line | cut -d " " -f 3` if [ $name != "#" ] then -w=$((w + 1)) - -if [ $age -ge $inWiek ] +if [ $country = "$2" -a $age -ge $3 ] then - kraje["$country"]=$((kraje["$country"] + 1)) echo "Person $name (from $country) is $age years old" fi fi -done < $inPlikWej - -for key in ${!kraje[@]}; do echo "From $key there is ${kraje["$key"]} persons"; done +done < $1 From 476db2675690c93098ec51d0ae6a4d2e0f3a0808 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 15 May 2023 17:31:18 +0200 Subject: [PATCH 2/4] remove obsolete file --- tabledata/screenshare | 1 - 1 file changed, 1 deletion(-) delete mode 100644 tabledata/screenshare diff --git a/tabledata/screenshare b/tabledata/screenshare deleted file mode 100644 index 029b907..0000000 --- a/tabledata/screenshare +++ /dev/null @@ -1 +0,0 @@ -https://meet.jit.si/unixsysop From c7b1fb7e0f027c38fc5789894b0b365cb4cfdd93 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 15 May 2023 17:38:24 +0200 Subject: [PATCH 3/4] Reading input data in the console, not from arguments --- tabledata/ex1.sh | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/tabledata/ex1.sh b/tabledata/ex1.sh index 04162d0..2b562c6 100755 --- a/tabledata/ex1.sh +++ b/tabledata/ex1.sh @@ -4,6 +4,14 @@ #numOfPeople=`cat $1 | grep $2 | wc -l` #echo "Num. of people from $2 is $numOfPeople" +echo "Podaj plik z danymi" +read inPlik +echo "Podaj wiek" +read inWiek +echo "Podaj kraj" +read inKraj + + # iterating line-by-line while read line do @@ -15,11 +23,11 @@ country=`echo $line | cut -d " " -f 3` if [ $name != "#" ] then -if [ $country = "$2" -a $age -ge $3 ] +if [ $country = "$inKraj" -a $age -ge $inWiek ] then echo "Person $name (from $country) is $age years old" fi fi -done < $1 +done < $inPlik From d7c3c77ef72bf83d1cd5673f9745bbca595bf0f3 Mon Sep 17 00:00:00 2001 From: Arkadiusz Hypki Date: Mon, 15 May 2023 18:05:39 +0200 Subject: [PATCH 4/4] 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"