我有一个输入文件p.txt
,我想要计算和分类,我似乎没有得到所需的输出。
输入文件:
A1 G1 C1 F1
A2 G1 C1 F1
A3 G1 C1 F2
A4 G1 C2 F2
A7 G1 C2 F2
A8 G1 C2 F3
A11 G1 C2 F3
A23 G1 C2 F3
B4 G1 C2 F3
AC4 G2 C3 F4
B6 G2 C4 F4
BB5 G2 C4 F4
A25 G2 C5 F4
B13 G2 C5 F5
D12 G2 C5 F5
D2 G2 C5 F5
B89 G2 C5 F6
B44 G2 C5 F6
期望的输出:
G1(9)
F1(2)
C1=A1,A2
F2(3)
C1=A3
C2=A4,A7
F3(4)
C2=A8,A11,A23,B4
G2(9)
F4(4)
C3=AC4
C4=B6,BB5
C5=A25
F5(3)
C5=B13,D12,D2
F6(2)
C5=B89,B44
我试过了:
awk '{
D[$2]++
A[$4]++
B[$4 FS $3] = B[$4 FS $3] ? B[$4 FS $3] "," $1 : $1
if(!tmp[$4 FS $3]++)order[++c]=$4 FS $3
}
function orderp(subs,mains){
for(j in B){
if(j==subs){
split(j,X)
if(X[1]==mains)
print X[2]"="B[j]
}
}
}
END{
for(i in D){
print i"("D[i]")"
for(i in A){
print i"("A[i]") "
for(m=1;m<=c;m++){ orderp(order[m],i) }
print ""
}
}
}
' p.txt
我没有得到所需的输出 这就是我得到的:
G1(9)
F1(2)
C1=A1,A2
F2(3)
C1=A3
C2=A4,A7
F3(4)
C2=A8,A11,A23,B4
F4(4)
C3=AC4
C4=B6,BB5
C5=A25
F5(3)
C5=B13,D12,D2
F6(2)
C5=B89,B44
G2(9)
F1(2)
C1=A1,A2
F2(3)
C1=A3
C2=A4,A7
F3(4)
C2=A8,A11,A23,B4
F4(4)
C3=AC4
C4=B6,BB5
C5=A25
F5(3)
C5=B13,D12,D2
F6(2)
C5=B89,B44
答案 0 :(得分:0)
您需要创建CSS
特定子数组。这是对您的代码的修复:
G