Subscribe to Get Free Material Updates!
Visit my new blog WebData Scraping - Web Scraping Service provider company in India.

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


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`
done


Output: 

2 comments:

Shivesh Tips & Tricks said...

How to Execute this Code..?

keval kothari said...

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

Related Posts Plugin for WordPress, Blogger...

 
Design by Wordpress Theme | Bloggerized by Free Blogger Templates | coupon codes