|
[root@shpdl380prx2 nm308]# cat data5
130 120 135
160 113 140
145 170 215
[root@shpdl380prx2 nm308]# awk '{ total = 0;i=1;while(i<4) {total +=$i; i++} avg =total /3;print "Average:",avg }' data5
Average: 128.333
Average: 137.667
Average: 176.667
大多数都能看懂,但不理解为什么最后把除余3后的值都累加起来。
130/3=43.333 120/3=40 135/3=45 Average: 128.333=43.333+40+45 |
|