root@client.example.com # cat 1.txt
jack huaxue 90
tom huaxue 86
jack shuxue 99
tom shuxue 80
要求算出jack和tom的2科的平均分 用shell实现。
注意变量与大括号的间隔
root@client.example.com # awk '{ a[$1] += $3 } end { for (i in a ) print i,a[i]/2 }' 1.txt
root@client.example.com # awk '{a[$1]+=$3}END{ for (i in a)print i,a[i]/2 }' 1.txt
jack 94.5
tom 83
jack huaxue 90
tom huaxue 86
jack shuxue 99
tom shuxue 80
要求算出jack和tom的2科的平均分 用shell实现。
注意变量与大括号的间隔
root@client.example.com # awk '{ a[$1] += $3 } end { for (i in a ) print i,a[i]/2 }' 1.txt
root@client.example.com # awk '{a[$1]+=$3}END{ for (i in a)print i,a[i]/2 }' 1.txt
jack 94.5
tom 83
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/22664653/viewspace-689302/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/22664653/viewspace-689302/