I have input piped to awk on a macOS system. I want the sum of two decimal values. One occurs every second row, the other is on every fourth row. I want the result of the sum on every fifth row. The values are delimited by colon+space before, and a comma after. Every sixth row is empty. This pattern repeats until end of the input.
BB: 728345643856359022,
SH: 3560836,
RJ: 1500369,
DD: 1403849,
Total:,
BB: 729586953244932948,
SH: 8560836,
RJ: 4700360,
DD: 3403021,
Total:,
BB: 821334125345384020,
SH: 5293431,
RJ: 2642499,
DD: 2433292,
Total:,
If relevant, which awk
outputs /usr/bin/awk
and brew list --version
outputs gawk 5.2.1_1
. Is this possible in g/awk? Any advice appreciated!
To format the input I am using:
getlist | awk '{print $1 $2}' \
| grep 'BB\|SH\|RJ\|DD' \
| sed 's/"//g' \
| awk '{print;} NR % 4 == 0 { print "Total:,";}' \
| awk '{print;} NR % 5 == 0 { print "";}' \
| awk '{print $1 $2}'
Expected output
BB: 728345643856359022,
SH: 3560836,
RJ: 1500369,
DD: 1403849,
Total: 4964685,
BB: 729586953244932948,
SH: 8560836,
RJ: 4700360,
DD: 3403021,
Total: 11963857,
BB: 821334125345384020,
SH: 5293431,
RJ: 2642499,
DD: 2433292,
Total: 7726723,