46 lines
993 B
Bash
Executable File
46 lines
993 B
Bash
Executable File
#!/bin/bash
|
|
|
|
# iterating line-by-line over the input file
|
|
#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
|
|
|
|
wszyscy=0
|
|
|
|
declare -A kraje
|
|
|
|
# iterating line-by-line
|
|
while read line
|
|
do
|
|
|
|
name=`echo $line | cut -d " " -f 1`
|
|
age=`echo $line | cut -d " " -f 2`
|
|
country=`echo $line | cut -d " " -f 3`
|
|
|
|
if [ $name != "#" ]
|
|
then
|
|
|
|
wszyscy=$((wszyscy+1))
|
|
|
|
if [ $age -ge $inWiek ]
|
|
then
|
|
kraje["$country"]=$((kraje["$country"]+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"
|
|
#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
|