美文网首页
2019-05-14

2019-05-14

作者: chenjinlong | 来源:发表于2019-05-14 20:06 被阅读0次

    日志文本筛选-sort awk

    求最大值:

    awk 'BEGIN {max = 0} {if ($1+0 > max+0) max=$1} END {print "Max=", max}' test.txt
    

    求最小值:

    awk 'BEGIN {min = 65536} {if ($1+0 < min+0) min=$1} END {print "Min=", min}' test.txt
    

    求和:

    cat test.txt|awk '{sum+=$1} END {print "Sum= ", sum}'
    

    求平均值:

    cat test.txt|awk '{sum+=$1} END {print "Avg= ", sum/NR}'
    

    求最大值

    cat test.txt|awk 'BEGIN {max = 0} {if ($1>max) max=$1 fi} END {print "Max=", max}
    

    求最大值

    cat test.txt|awk 'BEGIN {max = 0} {if ($1+0>max+0) max=$1 fi} END {print "Max=", max}'
    

    求最小值

    cat test.txt|awk 'BEGIN{min = 65536}{if ($1+0<min+0) min=$1 fi}END{print "Min=", min}'
    

    中位数

    #/usr/bin/env awk
    {
      count[NR] = $1;
    }
    END {
        if (NR % 2) {
            print count[(NR + 1) / 2];
        } else {
            print (count[(NR / 2)] + count[(NR / 2) + 1]) / 2.0;
        }
    }
    

    相关文章

      网友评论

          本文标题:2019-05-14

          本文链接:https://www.haomeiwen.com/subject/axoeaqtx.html