I have a project in Bash and I need a way of calculating averages of students and adding those averages in a text file. The text file is the following:
:NOM Prenom:CODE :.Tp1 :.Intra:.Tp2 :.Tp3 :.Final :.TP4 :.Moy:.Lettre:
actarusx:Actarus :ACTA28658105 : 45.5: 75.00:100.0: 95.0: 48.50: 90.0:
alcorxxx:Alcor :ALCO18083408 : 83.0: 64.75: 95.0: 87.5: 74.00: 97.0:
venusiax:Venusia :VENU13097708 : 83.0: 55.00: 95.0: 87.5: 41.50: 97.0:
phenicia:Phenicia :PHEN14100790 : 94.0: 50.50: 95.0: 95.0: 59.50: 99.0:
mizarxxx:Mizar :MIZA22128106 : 98.0: 95.50: 95.0:100.0: 80.50: 90.0:
procyonx:Procyon :PROC01033701 : 99.0: 99.50:100.0: 95.0: 98.00:100.0:
flamxxxx:Flam :FLAM26077904 : 89.0: 37.25: 97.5: 87.5: 63.50: 97.0:
johannxx:johann :JOHA23058000 : 94.0: 99.25:100.0: 95.0: 36.00:100.0:
wrightxx:Wright :WRIG21058103 : 99.0: 100.0:100.0:100.0: 100.0: 97.0:
cragxxxx:Grag :CRAG05018002 : 99.0: 90.00: 90.0:100.0: 97.00: 99.0:
malaxxxx:Mala :MALA09557914 : 96.0: 69.50:100.0:100.0: 34.00: 47.0:
I want to calculate the total average of TP1,2,3,4, Intra and Final. Once I have the average for each student (one student per line), I want to add the average under the column called Moy:. Note: For some reason, the categories all got moved around so the first line of floats is associated with tp1 and so forth.
At the moment I have:
nbline=0
while read line; do
if[ $nbline -eq 0 ]; then #To skip the first line with each categories
let nbline+=1
else
# Code that allows me to get the grades for each categories (already provided by the teacher)
# eg. for the first student the code will do tp1=45.5, intra=75, etc...
# Code that allows me to calculate the average (already provided by the teacher)
# moy is the average found
Once I find moy, I'm not sure how to add it in the column Moy: of each student. This is my first time coding in unix/linux and my teacher didn't spend a lot of time (if any at all) teaching us the different commands so help would be greatly appreciated.
Thank you very much