我必须过滤如下行:
[javac] /Users/looris/Sviluppo/android/projects/toutry/src/net/looris/toutry/Stuff.java:23: warning: unmappable character for encoding ascii
[javac] return (poked=false); // NOTA: è un'assegnazione, non un controllo!
[javac] ^
我已尝试过|grep -v -A2 "unmappable character for encoding ascii"
但没有任何效果。
如果我|grep -v "unmappable character for encoding ascii"
这么做做过滤该行,但我也需要过滤以下两行。
(在 OSX 10.5 下使用“grep (GNU grep) 2.5.1”)
答案1
如果您调用grep -A2 -v
,当包含搜索模式的行超过 2 行时,它将开始跳过这些行,这显然不是您想要的。试试这个:
| awk 'BEGIN { skip = 0 } /unmappable character for encoding ascii/ { skip = 3 } { if (skip > 0) { skip-- } else { print $0 } }'
AWK代码展开如下:
BEGIN {
skip = 0
}
/unmappable character for encoding ascii/ {
skip = 3
}
{
if (skip > 0) {
skip--
} else {
print $0
}
}