LAB ASSIGNMENT 8 Write a shell script invoking awk to produce a grade report for
ID: 3733298 • Letter: L
Question
LAB ASSIGNMENT 8 Write a shell script invoking awk to produce a grade report for a class. The script should be named grade report and will be invoked by grade_report [grade_file] [project file] [level file] If any file names are omitted, please use "grades", "projects" and "levels" as defaults. In other words if one file name is given, it is the grade file. If two file names are given, the first is the grade file and the second is the project file The Grades File: The grades file wil contain one line per student with the student's name and grades separate by colons. An example grades file is John Bunyan:90:100:75:60 Maria Montessori:80:90:60:82 Alice Cooper:75:80:54:47 Harvey Mudd: 89:45:89:95 The Project File: The project file should containe for each project assigned with the project's name and weight separated by colons. An example project file is test1:30 test2:30 paper: 20 exam:50 You will note that the weights are relative and need not add up to 100. In this case the total of the weights is 130
Explanation / Answer
Answer :
#line1 contains all the lines of grades file
while read line1
do
# average contains average of all the marks of a particular student
avg=`echo $line1|sed -e 's/:/ /g'|gawk 'END {print ($3+$4+$5+$6)/4}'`
stu=`echo $line1|sed -e 's/:/ /g'`
# line contains the contents of levels file
while read line
do
# grade contains the marks present in levels file
grade=`echo $line|sed -e 's/:/ /g'|gawk 'END {print $2}'`
# grade_value contains A,B,C,D present in levels file
grade_value=`echo $line|sed -e 's/:/ /g'|gawk 'END {print $1}'`
#std does the float comparison between the obtained grade and the students grade
std=`echo "$avg>$grade"|bc`
if [ "$std" -eq 1 ]
then
final_grade=$grade_value
echo $stu" "$avg" "$grade_value
break
fi
done<level
done<grade
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.