Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #if there is not exactly 1 argument
- if [ $# -ne 1 ]
- then
- echo "USAGE: `basename $0` file_name.csv"
- exit 1
- fi
- #if the argument don't exist
- if [ ! -f $1 ]
- then
- echo "Ne postoi taa datoteka. Probaj pak!"
- exit 1
- fi
- FILENAME=`echo $1 | awk -F. '{print $1}'`
- #if the output file exists, delete it, then create it again
- if [ -f passed_${FILENAME}.csv ]
- then
- rm passed_${FILENAME}.csv
- fi
- touch passed_${FILENAME}.csv
- echo "Surname,\"First name\",Index,Points" >> passed_${FILENAME}.csv
- SODRZINA=`cat $1 | grep [0-9] | awk -F, '$4>4 {print $0}'`
- NUMBER_PASSED=`cat $1 | grep [0-9] | awk -F, '$4>4 {print $0}' | wc -l`
- TOTAL_POINTS=0
- for line in $SODRZINA
- do
- POINTS=`echo $line | awk -F, '{print $4}'`
- TOTAL_POINTS=`expr $TOTAL_POINTS + $POINTS`
- echo $line >> passed_${FILENAME}.csv
- done
- AVERAGE=`expr $TOTAL_POINTS / $NUMBER_PASSED`
- echo "Average points of passed students is: ${AVERAGE}!" >> passed_${FILENAME}.csv
- cat passed_${FILENAME}.csv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement