我有一系列目录
079/af3
100/af4
120/af3
  . 
  .
  .
每个???/af?目录都包含一个很长的文件results.stdout。接近这个文件的结尾,可以找到字符串
 Normal termination: iterations complete!
如果 af3 (resp. af4) 中的计算成功,则在文件中写入一条或多条错误消息。为了避免手动检查每个文件,我正在编写一个生成摘要文件的脚本:
 Massflow        af3      af4 
      079    Success  Failure
      100    Failure  Success
      120    Success  Success
        .      .       .
        .      .       .
到目前为止,我已经能够烹饪以下内容:
#!/bin/bash
strlen="9" # want to keep the format flexible, instead than hardcode it
format0="%"$strlen"s %"$strlen"s %"$strlen"s\n"
# write the header of file summary
awk -v format="$format0" ' BEGIN { printf format, "Massflow", "af3", "af4"
                             } ' >> summary
for dir in ??? # loop on all the directories
do
    for j in 3 4 # loop on the two subdirs
    do
    result[$j]=$(tac $dir/af$j/results.stdout | awk '
    /TACOMA:- Normal termination: iterations complete!/ {success = 1; exit}
    END { if (success == 1)
              print "Success"
          else
              print "Failure"
        }')
    done
done
exit 
但是,我不知道如何编写摘要文件...我想将result数组传递给另一个 awk 程序,但 awk 不接受数组变量。有什么建议么?如果您认为我的编程风格、工具选择或两者都很糟糕,请随意更改方法甚至工具:)