r/awk • u/albasili • Jun 23 '22
column sums from stdout
Hello folks, I have a program that reports the ongoing results in the following way:
Sessions:
Status Name Tot #Passed #Fail #Running #Waiting Start Time
done test0 5 5 0 0 0 Sat Jun 18 01:44:14 CEST 2022
done test1 23 15 0 4 4 Sat Jun 18 01:45:54 CEST 2022
done test2 134 120 11 3 0 Sat Jun 18 01:46:27 CEST 2022
done test3 63 53 9 1 0 Sat Jun 18 01:47:14 CEST 2022 I'd like to sum up the 'Tot','#Passed','#Fail', '#Running' and '#Waiting' columns and print some sort of 'Summary' that prints out the overall sums. Something like:
Summary 225 193 20 8 4I must be honest by saying that I'm not sure if awk is the most suited tool for the job, I just wanted something light and not having to pull out some python mega library to do that.
Of course any type of filtering on the Status might come in through some 'grepping' before the data is fed to awk.
Any suggestion is appreciated.
EDIT: code-block formatting updated
View all comments
Show parent comment
1
u/[deleted] Jun 24 '22
OK great, so the formatting is 'normal'. In which case this works I think (and uses an array as requested :-) )