本节内容:
awk统计命令
1、求和
cat data|awk '{sum+=$1} END {print "Sum = ", sum}'
2、求平均
cat data|awk '{sum+=$1} END {print "Average = ", sum/NR}'
3、求最大值
cat data|awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Max=", max}'
4、求最小值(min的初始值设置一个超大数即可)
awk 'BEGIN {min = 1999999} {if ($1<min) min=$1 fi} END {print "Min=", min}'
原创文章,作者:ItWorker,如若转载,请注明出处:https://blog.ytso.com/3062.html