awk列计算

半日闲 2020年07月16日 38次浏览

awk列计算

  1. 文件内容

    cat file.log
    I0716 09:08:08.2423 887 client.h:79] client delay 32525235
    I0716 09:08:08.2423 887 client.h:79] client delay 32525235
    I0716 09:08:08.2423 887 client.h:79] client delay 32525235
    ​```
    
  2. 计算脚本

    cat jisuan.sh
    #!/bin/bash
    File=$1
    for Column in "inference" "client"
    do
    	avg=`grep $Column $File|awk '{sum+=$NF}END{print sum/NR}'`
    	min=`grep $Column $File|awk 'BEGIN{min=999999}{if($NF+1<min+1) min=$NF}END{print min}'`
    	max=`grep $Column $File|awk 'BEGIN{max=0}{if($NF+1>max+1) max=$NF}END{print max}'`
    	echo avg, min, max
    done