Advertisement
dzocesrce

[OS] Passed OS Students

Jan 21st, 2024 (edited)
607
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.02 KB | None | 0 0
  1. #!/bin/bash
  2. #if there is not exactly 1 argument
  3. if [ $# -ne 1 ]
  4. then
  5.     echo "USAGE: `basename $0` file_name.csv"
  6.     exit 1
  7. fi
  8. #if the argument don't exist
  9. if [ ! -f $1 ]
  10. then
  11.         echo "Ne postoi taa datoteka. Probaj pak!"
  12.         exit 1
  13. fi
  14. FILENAME=`echo $1 | awk -F. '{print $1}'`
  15. #if the output file exists, delete it, then create it again
  16. if [ -f passed_${FILENAME}.csv ]
  17. then
  18.         rm passed_${FILENAME}.csv
  19. fi
  20. touch passed_${FILENAME}.csv
  21. echo "Surname,\"First name\",Index,Points" >> passed_${FILENAME}.csv
  22.  
  23. SODRZINA=`cat $1 | grep [0-9] | awk -F, '$4>4 {print $0}'`
  24. NUMBER_PASSED=`cat $1 | grep [0-9] | awk -F, '$4>4 {print $0}' | wc -l`
  25. TOTAL_POINTS=0
  26.  
  27. for line in $SODRZINA
  28. do
  29.         POINTS=`echo $line | awk -F, '{print $4}'`
  30.         TOTAL_POINTS=`expr $TOTAL_POINTS + $POINTS`
  31.         echo $line >> passed_${FILENAME}.csv
  32. done
  33. AVERAGE=`expr $TOTAL_POINTS / $NUMBER_PASSED`
  34. echo "Average points of passed students is: ${AVERAGE}!" >> passed_${FILENAME}.csv
  35. cat passed_${FILENAME}.csv
  36.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement