I have two files. One contains students and their average grade from the first semester and the second contains students and 5 grades from the second semester. I have to update the first file, so that it contains the students sorted after the yearly average grade. I'm new to unix and so far I've tried to use the awk command within an awk but I keep getting a syntax error. I have tried other ways but all I can manage to achieve is separating the file contents into lines, without direct access to the second word(the average grade) from each line.
input files:
firstsem:
Name1 6
Name2 8
Name3 10
secondsem:
Name1 5 6 5 6 5
Name2 10 10 10 10 10
Name3 2 2 2 2 2
result:
firstsem:
Name1 5.7
Name3 6
Name2 9
Code:
awk '{
name = $1
total=$2+$3+$4+$5+$6;
avg=total/5;
print name " " avg
#sprintf("",nume,avg)
}' < secondsem > secondsemesteravg
# i didn't really want the secondsemesteravg file, but i didn't find another way
while read line; do
# wanted to get the avg from firstsem
echo $line | awk '{$2=avgfirstsem + avgsecondsem/2; print $0;}';
done < firstsem