从grep管道中排除整个blob

问题描述 投票:0回答:1

因此,我有一些日志文件,其中包含一堆异常堆栈跟踪。我要尝试做的是获取堆栈跟踪(如果存在特定的异常消息),然后如果该Blob中存在特定的方法签名,则排除整个Blob,最后写入文件。

所以举个例子,

zgrep -A 65 "Exception Message to Grep For" FileNamePrefix* | grep -v "exclude function name" > storage_file.txt

最终发生的情况是,grep搜索“要发送给Grep的异常消息”并得到一行blob,但是第二个grep只是删除了一行“ exclude function name”,并保存了其余blob到存储文件。

[我正在尝试做的是忽略第二个grep中的整个blob,如果该blob中存在“排除函数名称”文本。

使用grep可以实现这一目标吗?

bash grep pipe blob ignore
1个回答
0
投票

您可以使用awk

   awk '/Exception Message to Grep For/ && !/exclude function name/{x=NR+65}(NR<=x){print}' filename

这将查找与Exception Message to Grep For匹配但没有exclude function name的行,如果找到,它将打印接下来的65行。

© www.soinside.com 2019 - 2024. All rights reserved.