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

#SAMPLE DATA
#1,abc,56,89,42
#2,def,74,65,40
#3,ghi,24,36,51
#4,jkl,74,85,90
#5,mno,25,32,36
#6,pqr,85,92,97

clear
dbfile="studentdata"
count=1
for i in `cat $dbfile`
do
    no=$(echo $i|tr -s " "|cut -d "," -f1)
	name=$(echo $i|tr -s " "|cut -d "," -f2)
	m1=$(echo $i|tr -s " "|cut -d "," -f3)
	m2=$(echo $i|tr -s " "|cut -d "," -f4)
	m3=$(echo $i|tr -s " "|cut -d "," -f5)
	total=$(echo $m1+$m2+$m3 | bc -l)
	echo "======================================================="
	echo "STUDENT "$count
	echo "======================================================="
	echo "Roll no. :"$no
	echo "Name "$name
	echo "Subject -1 :"$m1
	echo "Subject -2 :"$m2
	echo "Subject -3 :"$m3
	echo "Grand total :"$total
	echo "Percentage :"$(echo "scale=2;$total / 3" | bc -l)
	count=$(echo $count + 1 | bc -l)
done
if [ $count -eq 0 ]
then
	echo "No records for students"
fi