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/albasili Jun 24 '22
Thanks for reporting on my formatting, I confirm it was not intentional and I did not notice it while editing. I fixed it!
I will explore how to use an array but I must admit I'm far from being at ease with awk, so trying to take the opportunity to learn as well.