我想在/ ERROR /匹配之前打印行。要打印的行应全部包含INFO,直到找到先前的ERROR。
所以如果我有一个文件
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}'
答案 0 :(得分:0)
尝试这一个班轮:
awk 'x;/ERROR/{x=1}' file
输出:
INFO error found on line 2
INFO error is due to something
ERROR this is another error
长版:
x;/ERROR/{
x1=1;
print
}
如果" ERROR"找到x = 1,如果x为真,我们已经通过该行,然后我们打印直到我们再次通过该行。
或许这个,我不太清楚你需要什么输出。
awk '/ERROR/{x=1;next}/ERROR/{x=1}x'
停止
INFO error found on line 2
INFO error is due to something