我想搜索許多.log文件以查找特定的錯誤。下面的shell代碼給了我,我要檢查它規定在最後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
每行對應於一個.log文件。現在我想比較這兩個整數並只在整數相同的情況下打印文件名。
你可以發佈你的日誌文件的樣本(最後幾行)嗎?管道過多... –