跟踪单个awk可能会帮助您。
sar -r -f | awk '
FNR>1&&!/memused/{
max=max>$5?max:$5;
min=min>$5?$5:(min?min:$5);
sum+=$5}
END{
print "Minimum:",min,"Average:",(sum/FNR),"Maximum:",max
}'
编辑:现在也添加了代码说明。
sar -r -f | awk ' ## Sending sar standard output as a standard input by pipe to awk command.
FNR>1&&!/memused/{ ## checking if line number is greater than and not having string memused in it then do following.
max=max>$5?max:$5; ## creating a variable named max and checking if max variable value is greater than 5th field then keep it as max else keep it as 5th field to get the maximum values.
min=min>$5?$5:(min?min:$5); ##creating a variable named min and checking if min value is greater than 5th field if yes then change its value to $5 or check if min is there keep its value to min or if min is NULL then keep it as $5 value.
sum+=$5} ## creating variable named sum and adding its value to itself along with 5th fields value.
END{
print "Minimum:",min,"Average:",(sum/FNR),"Maximum:",max ##Printing string minimum and min value similarly with avg and maximum too.
}'