Bash脚本不返回任何值

时间:2018-03-12 16:22:29

标签: bash

    #!/bin/bash
    for i in $(ls $1); do
    echo -n $i | sed 's/.dat//g'
    grep '<Overall>' $i | sed 's/<Overall>//g'
    awk 'BEGIN{sum=0} {sum+=$1} END{print sum/NR}'
    sed -re 's/([0-9]+\.[0-9]{2})[0-9]+/\1/g'
    echo 1
    done | sort -nrk2

此脚本应返回平均整体评分。我找不到错误,因为我没有得到任何输出。

1 个答案:

答案 0 :(得分:0)

未经测试:

gawk -F'>' '
    BEGINFILE {sum = n = 0}
    $1 == "<Overall" {sum += $2; n++}
    ENDFILE {print FILENAME, (n == 0) ? "n/a" : sum/n}
' *.dat