This is homework. I have to write a bash shell script using awk to process three delimited text files and produce a formatted report. The three files are as follows:
GRADES file
John Bunyan:90:100:75:60
Maria Montessori:80:90:60:82
Alice Cooper:75:80:54:47
Harvey Mudd:89:45:89:95
PROJECTS file
test1:30
test2:30
paper2:20
exam:50
LEVELS file
A:89.5
B:79.5
C:69.5
D:59.5
F:0
I hope this is fairly easy to see how these relate. The object is to go through each student, weight their grades, and output the corresponding letter grade. The awk script I have so far looks like it should work, but I am getting numerous errors, mostly of a few types. Here is the script:
#!/bin/bash
FILEGRADES=grades
FILEPROJ=projects
FILELEVEL=levels
awk '
titleline[0]="Name"
z=1
while ( (getline < "FILEPROJ") > 0) {
titleline[z]=$1
weights[m]=$2
z++
m++
}
for (n = 0, n < m, n++) {
ttlwght=$ttlwght+$weights[n]
}
titleline[z]="average"
for (y = 0, y < z, y++){
print $titleline[y]
print "\t"
}
while ( (getline < "FILELEVEL") > 0) {
gradelvl[a]=$1
gradereq[a]=$2
a++
}
while ( (getline < "FILEGRADES") > 0) {
for(i = 2, i <= NF, i++){
gradesum=$i*$weights[i-1]
}
fingrade=$gradesum/$ttlwght
print $fingrade
for(c = 0,c < a,c++) {
if (fingrade>gradereq[c]) {
then
print gradelvl[c]
else
fi
}
}
' FILEGRADES FILEPROJ FILELEVEL
The errors I am getting are of only a few types:
(1) Syntax error (beginning and end of each loop declaration (at the "for" or "while" and at the "{" bracket))
(2) 'unexpected newline or end of string' (end of every assignment option like "gradelvl[a]=$1", and also end of the statement "print gradelvl[c]")
Not sure what I'm doing wrong, but if anyone can help, that would be great.
Thanks.