- 论坛徽章:
- 1
|
第二是这样的吧
/home/lee#cat file
zhanghong:class1:75
wangliang:class2:68
liming:class3:99
dave:class2:83
liuhai:class3:23
fangyuan:class1:77
zhanghong:class1:75
wangliang:class2:68
liming:class3:99
dave:class2:83
liuhai:class3:23
fangyuan:class1:77
- /home/lee#\
- > cut -f2 -d':'<file|sort -u|xargs -i awk -F: '/{}/{n++;sum[$2]+=$3}
- > END{for(i in sum)printf "%s: %s,%s %.2f\n",i,n" persons",
- > "average:",sum[i]/n}' file
复制代码class1: 4 persons,average: 76.00
class2: 4 persons,average: 75.50
class3: 4 persons,average: 61.00
[ 本帖最后由 寂寞烈火 于 2005-11-21 01:53 编辑 ] |
|