• Source
    1. #
    2. #Write a script for generating a mark sheet after reading data from a file.
    3. #File contains student roll no, name , marks of three subjects.
    4. #
    5.  
    6. #SAMPLE DATA
    7. #1,abc,56,89,42
    8. #2,def,74,65,40
    9. #3,ghi,24,36,51
    10. #4,jkl,74,85,90
    11. #5,mno,25,32,36
    12. #6,pqr,85,92,97
    13.  
    14. clear
    15. dbfile="studentdata"
    16. count=1
    17. for i in `cat $dbfile`
    18. do
    19. no=$(echo $i|tr -s " "|cut -d "," -f1)
    20. name=$(echo $i|tr -s " "|cut -d "," -f2)
    21. m1=$(echo $i|tr -s " "|cut -d "," -f3)
    22. m2=$(echo $i|tr -s " "|cut -d "," -f4)
    23. m3=$(echo $i|tr -s " "|cut -d "," -f5)
    24. total=$(echo $m1+$m2+$m3 | bc -l)
    25. echo "======================================================="
    26. echo "STUDENT "$count
    27. echo "======================================================="
    28. echo "Roll no. :"$no
    29. echo "Name "$name
    30. echo "Subject -1 :"$m1
    31. echo "Subject -2 :"$m2
    32. echo "Subject -3 :"$m3
    33. echo "Grand total :"$total
    34. echo "Percentage :"$(echo "scale=2;$total / 3" | bc -l)
    35. count=$(echo $count + 1 | bc -l)
    36. done
    37. if [ $count -eq 0 ]
    38. then
    39. echo "No records for students"
    40. fi