本人因为现在对Linux的shell编程不是很熟悉,但现在遇到一个要及时需要解决的小问题。我想对以下的数据按第二列对其进行统计计数,最后输出A,B和C各包括了多少? 请高手指点一下。
A10 A 0.65000000 0.04500000 0.41300000
A11 A 0.81000000 0.55000000 0.56300000
A2 A 0.15000000 0.54500000 0.41300000
A3 A 0.31000000 0.05000000 0.56300000
B12 B 0.66700000 0.99400000 0.17500000
B13 B 0.47500000 0.99500000 0.47000000
B14 B 0.70000000 0.33400000 0.46700000
B15 B 0.75000000 0.83400000 0.52500000
B16 B 0.81900000 0.50400000 0.80000000
B4 B 0.16700000 0.49400000 0.17500000
B5 B 0.97500000 0.49500000 0.47000000
B6 B 0.20000000 0.83400000 0.46700000
B7 B 0.25000000 0.33400000 0.52500000
B8 B 0.31900000 0.00400000 0.80000000
C1 C 0.00000000 0.00000000 0.00000000
C9 C 0.50000000 0.50000000 0.00000000
hummer613 于 2007-11-20 16:07:34发表:
楼上的怎么这么怪? 积分怎么是负的?
xcwen 于 2007-11-19 09:46:13发表:
#!/usr/bin/awk -f
BEGIN {
A=0
B=0
C=0
}
{
if ( $2 == "A" ){
A=A+1
}else if( $2 == "B" ) {
B=B+1
}else if( $2 == "C" ) {
C=C+1
}
}
END{
printf "A[%d],B[%d],c[%d] " , A , B , C
}