age.sh 1006 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # File: age.sh
  2. # Name: D.Saravanan Date: 24/02/2020
  3. # Bash script to display number of persons in a given age group
  4. while read line
  5. do
  6. echo "$line"
  7. done < list.csv
  8. min=`cat list.csv | tail -n +2 | cut -d "," -f 3 | sort -n | head -1`
  9. max=`cat list.csv | tail -n +2 | cut -d "," -f 3 | sort -n | tail -1`
  10. echo "Enter lower limit age: "
  11. read ll
  12. if [ $ll -lt $min ]
  13. then
  14. echo "The minimum age value in the list is $min."
  15. echo "Enter lower limit age: "
  16. read ll
  17. fi
  18. echo "Enter upper limit age: "
  19. read ul
  20. if [ $ul -gt $max ]
  21. then
  22. echo "The maximum age value in the list is $max."
  23. echo "Enter upper limit age: "
  24. read ul
  25. fi
  26. count=0
  27. #No_of_entries=`cat list.csv | tail -n +2 | wc -l`
  28. #echo $No_of_entries
  29. #sorted_age_list=`cat list.csv | tail -n +2 | cut -d "," -f 3 | sort -n`
  30. #echo $sorted_age_list
  31. for n in `cat list.csv | tail -n +2 | cut -d "," -f 3`
  32. do
  33. if [ $n -ge $ll ] && [ $n -lt $ul ];
  34. then
  35. ((count++))
  36. fi
  37. done
  38. echo "The number of persons between the age $ll and $ul is $count."