clear len=`cat student.txt | wc -l` i=1 echo "\n\n\tSTUDENT MARKSHEET" echo "\t=================\n" echo "NAME \t \t TOTAL \t \t PERCENTAGE \t GRADE " echo "=====================================================" while [ $i -le $len ] do record=`head -n $i student.txt | tail -n 1` total=0 for (( j=2 ; $j < 5 ; j=`expr $j + 1` )) do marks=`echo $record | cut -d " " -f $j` total=`expr $total + $marks` done name=`echo $record | cut -d " " -f 1` per=`expr $total / 3` if [ $per -ge 85 ] && [ $per -le 100 ] ; then grade="AA" elif [ $per -ge 75 ] && [ $per -le 84 ] ; then grade="AB" elif [ $per -ge 65 ] && [ $per -le 74 ] ; then grade="BB" elif [ $per -ge 55 ] && [ $per -le 64 ] ; then grade="BC" elif [ $per -ge 45 ] && [ $per -le 54 ] ; then grade="CC" elif [ $per -ge 0 ] && [ $per -le 44 ] ; then grade="FAIL" else grade="-" fi echo "$name \t \t $total \t \t $per % \t \t $grade" i=`expr $i + 1` doneOutput:
2 comments:
How to Execute this Code..?
You can execute the above script in Unix shell. Open Unix shell and use sh command to execute the script.
Suppose you have saved above shell script file with name createfile.sh then you have to use below command to execute it.
sh createfile.sh
Post a Comment