I would like to calculate for each block/("team") a summary of $4 & $5 in awk
Sample input:
ABC Team
1109;BB; EE;B;M
1108;GG; KK;B;M
1104;KK; CC;F;S
1103;LL; JJ;B;XL
CBS Team
600;AA; AA;O;
597;AA; MM;O;
599;BB; JJ;B;M
593;DD; SS;B;S
UMG Team
7341;BB; TT;F;M
7339;FF; AA;B;M
7338;FF; SS;B;M
7336;GG; UU;B;XL
Desired output
ABC Team
1109;BB; EE;B;M
1108;GG; KK;B;M
1104;KK; CC;F;S
1103;LL; JJ;B;XL
B;M = 2
B;XL = 1
F;S = 2
CBS Team
600;AA; AA;O;
597;AA; MM;O;
599;BB; JJ;B;M
593;DD; SS;B;S
O; = 2
B;M = 1
B;S = 1
UMG Team
7341;BB; TT;F;M
7339;FF; AA;B;M
7338;FF; SS;B;M
7336;GG; UU;B;XL
F;M = 1
B;M = 2
B;XL = 1
This is the code I came up with, but does not work or have not found any code leading to the desired output. Can anybody help?
awk -F; "{if(NF>3) {a[$4 $5]++}} {if(NF==0) {for (pair in a) print pair, a[pair];a=0; pair=0}}1"
Edit - here's the above code formatted legibly by gawk -o-:
{
if (NF > 3) {
a[$4 $5]++
}
}
{
if (NF == 0) {
for (pair in a) {
print pair, a[pair]
}
a = 0
pair = 0
}
}
1 {
print
}
ABC Teamshow a predictedF;S = 2output? Should that beF;S = 1? Also,CBS Teamyou add across rows to countO; = 2values. How do you know theseOs can be added together? Is it possible that they have different 'partners' and thus should not be summed?