ex1.sh changed to make a statistics for all countries at once - it prints everything at the end
This commit is contained in:
parent
de44f3ece7
commit
2129be264a
@ -6,13 +6,12 @@
|
|||||||
|
|
||||||
echo "Podaj nazwę pliku z bazą danych"
|
echo "Podaj nazwę pliku z bazą danych"
|
||||||
read inPlikWej
|
read inPlikWej
|
||||||
echo "Podaj kraj, który wyszukać"
|
|
||||||
read inKraj
|
|
||||||
echo "Podaj minimalny wiek"
|
echo "Podaj minimalny wiek"
|
||||||
read inWiek
|
read inWiek
|
||||||
|
|
||||||
w=0
|
w=0
|
||||||
sz=0
|
|
||||||
|
declare -A kraje
|
||||||
|
|
||||||
# iterating line-by-line
|
# iterating line-by-line
|
||||||
while read line
|
while read line
|
||||||
@ -27,9 +26,9 @@ then
|
|||||||
|
|
||||||
w=$((w + 1))
|
w=$((w + 1))
|
||||||
|
|
||||||
if [ $country = "$inKraj" -a $age -ge $inWiek ]
|
if [ $age -ge $inWiek ]
|
||||||
then
|
then
|
||||||
sz=$((sz + 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
|
||||||
|
|
||||||
@ -37,4 +36,4 @@ fi
|
|||||||
|
|
||||||
done < $inPlikWej
|
done < $inPlikWej
|
||||||
|
|
||||||
echo "There is statistically `echo "scale=2; $sz/$w*100.0" | bc -l` % of such persons"
|
for key in ${!kraje[@]}; do echo "From $key there is ${kraje["$key"]} persons"; done
|
||||||
|
Loading…
Reference in New Issue
Block a user