postheadericon Write a script for generating a mark sheet after reading data from a file. File contains student roll no, name , marks of three subjects.


studInfo.txt

hitesh,30,70,80
mitesh,30,80,40
jitesh,30,35,40
ritesh,100,100,100

Ex13.sh

clear
len=`cat studInfo.txt | wc -l`
i=1
echo "\n\n\t\t\t [   STUDENT MARKSHEET  ]\n"
echo "__________________________________________________________________________"
echo "#\t NAME \t \t \t TOTAL \t \t PERCENTAGE \t GRADE "
echo "__________________________________________________________________________"

while [ $i -le $len ]
do
     record=`head -n $i studInfo.txt | tail -n 1`
     total=0
     j=2
     isFail=0
     while [ $j -le 4 ]
     do
        marks=`echo $record | cut -d "," -f $j`
        if [ $marks -lt 40 ]
        then
            isFail=1
        fi
        total=`expr $marks + $total`  
            j=`expr $j + 1`      
     done
     name=`echo $record | cut -d "," -f 1`
     per=`expr $total / 3`

    if [ $isFail = 0 ]
    then
        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"
         else
            grade="FF"
         fi
     else
           grade="FF"
        
     fi

     echo "$i \t $name \t \t $total \t \t $per % \t \t $grade"
     i=`expr $i + 1`
done
echo "__________________________________________________________________________\n"

0 comments:

Follow by Email

Total Pageviews

© BipinRupadiya.com. Powered by Blogger.