awk命令計算一列數值的總和,平均值,最大值,最小值
阿新 • • 發佈:2019-02-16
求和:
grep '' *.log | awk -F '(ms)' '{print $1}' | awk -F '' '{print $2}' | awk -F '(' '{print $1}' | awk '{print $1}' | awk '{sum+=$1}END{print sum}' 某列最大值:
grep '' *.log | awk -F 'time' '{print $2}' | awk -F ':' '{print $2}' | awk -F ',' '{print $1}' |awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}' 某列最小值: grep '' *.log | awk -F 'time' '{print $2}' | awk -F ':' '{print $2}' | awk -F ',' '{print $1}' |awk 'NR==1{min=$1;next}{min=min<$1?min:$1}END{print min}' 求平均值 : grep ' ' *.log | awk -F 'time' '{print $2}' | awk -F ':' '{print $2}' | awk -F ',' '{print $1}' | awk '{sum+=$1} END {print "Avg= ", sum/NR}'
某列數值長度大於3的資料:
grep '' *.log | awk -F 'time' '{print $2}' | awk -F ':' '{print $2}' | awk -F ',' '{print $1}' | awk '$1~/^.{3}$/{print $1}'
grep '' *.log | awk -F '(ms)' '{print $1}' | awk -F '' '{print $2}' | awk -F '(' '{print $1}' | awk '{print $1}' | awk '{sum+=$1}END{print sum}' 某列最大值:
grep '' *.log | awk -F 'time' '{print $2}' | awk -F ':' '{print $2}' | awk -F ',' '{print $1}' |awk 'NR==1{max=$1;next}{max=max>$1?max:$1}END{print max}' 某列最小值: grep '' *.log | awk -F 'time' '{print $2}' | awk -F ':' '{print $2}' | awk -F ',' '{print $1}' |awk 'NR==1{min=$1;next}{min=min<$1?min:$1}END{print min}' 求平均值 : grep ' ' *.log | awk -F 'time' '{print $2}' | awk -F ':' '{print $2}' | awk -F ',' '{print $1}' | awk '{sum+=$1} END {print "Avg= ", sum/NR}'
某列數值長度大於3的資料:
grep '' *.log | awk -F 'time' '{print $2}' | awk -F ':' '{print $2}' | awk -F ',' '{print $1}' | awk '$1~/^.{3}$/{print $1}'