- 论坛徽章:
- 0
|
继续 呵呵 我现在想对最后一列 进行分区间计算
awk '$NF>0&&$NF<300 {a[$1" "$2" "$3]+=1}END{for(i in a) print i,a,0} \
$NF>300&&$NF<600{a[$1" "$2" "$3]+=1}END{for(i in a) print i,a,300} \
$NF>600&&$NF<900{a[$1" "$2" "$3]+=1}END{for(i in a) print i,a,600} \
$NF>900&&$NF<1500{a[$1" "$2" "$3]+=1}END{for(i in a) print i,a,900} \
$NF>1500&&$NF<3000{a[$1" "$2" "$3]+=1}END{for(i in a) print i,a,1500} \
$NF>3000{a[$1" "$2" "$3]+=1}END{for(i in a) print i,a,3000}'`
算出的结果竟然是
+----------+----------+
| sum(Num) | Time_KEY |
+----------+----------+
| 5795718 | 0 |
| 5575218 | 300 |
| 5575218 | 600 |
| 5575218 | 900 |
| 5575218 | 1500 |
| 5575218 | 3000 |
+----------+----------+
后来知道原因是因为 END的关系,改了格式
awk 'if ( $NF>0&&$NF<300 ) {a[$1" "$2" "$3]+=1} \
else if ($NF>300&&$NF<600) {b[$1" "$2" "$3]+=1} \
else if ($NF>600&&$NF<900) {c[$1" "$2" "$3]+=1} \
else if ($NF>900&&$NF<1500) {d[$1" "$2" "$3]+=1} \
else if ($NF>1500&&$NF<3000) {e[$1" "$2" "$3]+=1} \
else{f[$1" "$2" "$3]+=1} END \
{for(i in a) print i,a,0; \
for(i in b) print i,b,300; \
for(i in c) print i,c,600; \
for(i in d) print i,d,900; \
for(i in e) print i,e,1500; \
for(i in f) print i,f,3000}'
又说句法错误 。。 |
|