特定のエラー発生について、多くの .log ファイルを検索したいと考えています。次のシェル コードは、最後の 5 行に「エラー終了」を示す各 .log ファイルをチェックする必要がある行を示しています。
for f in *.log; do
tail -n 5 "$f" | grep -q "Error termination" && tac "$f" | grep -m 1 "Step number";
done
これにより、次のような出力が得られます。
Step number 40 out of a maximum of 216
Step number 17 out of a maximum of 192
Step number 25 out of a maximum of 216
Step number 192 out of a maximum of 192
Step number 21 out of a maximum of 200
各行は 1 つの .log ファイルに対応します。ここで、2 つの整数を比較し、整数が同じ場合にのみファイル名を出力したいと考えています。