-1
我想在我的/ ERROR /匹配之前打印行。要打印的行應該都包含INFO,直到找到前一個ERROR。awk打印行之前匹配INFO直到匹配錯誤
所以,如果我有一個文件
ERROR this is an error
INFO error found on line 2
INFO error is due to something
ERROR this is another error
我想從ERROR this is another error
的/ ERROR /打印
INFO error found on line 2
INFO error is due to something
ERROR this is another error
任何人都知道嗎?我當前腳本的
部分:
/CRITICAL/ {
print "\x1b[93;1m"
}
/ERROR/ {
print "\x1b[37m"
}
/ERROR|EMERGENCY|CRITICAL/ {
if (NR == n+1) print "";
n = NR;
print x;print
print "\x1b[0m"
};{x=$0}'
編輯您的問題提供了大量樣本輸入集,包括你不想匹配的行。現在,根據文件的其他部分包含什麼以及您想要做什麼,可能會有太多答案。例如,如果在輸出段之間是否存在空白行,是否存在第三個ERROR行?不要在評論中回答 - 編輯您的問題以顯示更全面的輸入/輸出。 –