-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行?不要在评论中回答 - 编辑您的问题以显示更全面的输入/输出。 –