求和
cat file|awk '{sum+=$1} END {print "Sum = ", sum}' cat file|awk '{sum[$1]+=$2}END{for(c in sum){print c,sum[c]}}' #当第一列相同时,对应的第二列相加
求平均
cat fiile|awk '{sum+=$1} END {print "Average = ", sum/NR}'
求最大值
cat file|awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Max=", max}'
求最小值(min的初始值设置一个超大数即可)
cat file|awk 'BEGIN {min = 1999999} {if ($1<min) min=$1 fi} END {print "Min=", min}'
标签:END,sum,cat,命令,awk,file,print,统计 From: https://www.cnblogs.com/boye169/p/17144745.html