grep反转无法按我预期的方式工作

奥古斯托(Augusto)

我正在尝试从应用程序日志文件中复制一些文本,但我真的不明白为什么它不起作用...首先,我提取文件中可能有我想要的内容的每个部分,然后我想排除那些我不想说的话。问题是我想删除第一个grep发现的整个块,而不仅仅是行。我正在尝试:

grep -A 5 "header of start parts" file.log | grep -v "piece of unwanted words" -A 2 -B 3

因此,我认为使用-A 2和-B 3会删除第二个grep中的整个块,但事实并非如此。它仍然给我带来不需要的单词的结果……这是我文件的模式:

Some text to ignore
Some Text to ignore
header of start parts
line to get together
line to get together
line to get together
line to get together
line to get together
Some text to ignore
header of start parts
line to get together
line with piece of unwanted words
line to get together
line to get together
line to get together
A lot of other logs and this patterns repeating

所以我的第一个grep给了我所有这种情况:

header of start parts
line to get together
line to get together
line to get together
line to get together
line to get together

和这个:

header of start parts
line to get together
line with piece of unwanted words
line to get together
line to get together
line to get together

第二个grep我想排除我发布的所有第二个块。感谢您的任何帮助。

钢铁司机

由于grep有益划上下文块(默认情况下,使用--字符串),你可以在第一次的结果传递grepawk段落模式,并排除整个记录匹配第二个片段:

$ grep -A5 "header of start parts" file.log | 
  awk -vRS='\n--\n' '!/line with piece of unwanted words/'
header of start parts
line to get together
line to get together
line to get together
line to get together
line to get together

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

Android:OnItemClickListener无法按我预期的方式工作

不在,并且存在无法按我预期的方式工作

Java Scanner Delimeter无法按我预期的方式工作

grep regex括号无法按预期工作

@NotNull注释无法按预期方式工作

WhenTargetHas <>绑定无法按预期方式工作

javafx:绑定无法按预期方式工作

NSTask无法按预期/期望的方式工作

SwitchMap无法按预期的方式工作

iptables无法按我预期的方式工作:响应包与DNAT在PREROUTING中的预期不符

jQuery在追加和删除之间切换无法按我预期的方式工作

如果带有OR语句的公式无法按预期方式工作-我在做什么错?

Unity3d:Random.Range()无法按我预期的方式工作

无法并发按我期望的方式工作

Grep正则表达式无法按预期工作

jQuery Cookies无法在IE中按预期方式工作

isEnabled属性无法在Appium中按预期方式工作

Aspnet Core 3.1 Identity ConfirmEmail无法按预期方式工作

ifelse无法在R中按预期方式工作

FastAPI:无法使错误处理按预期方式工作

Golang:xml解组将无法按预期方式工作

自动填充无法在Excel中按预期方式工作

发现无法在Solaris 10中按预期方式工作

函数.contains()无法按预期方式在Groovy中工作

防火墙无法在kickstart中按预期方式工作

地图无法在python 3中按预期方式工作

以编程方式修改 ConstraintSet 链无法按预期工作

regexp无法在Octave中按预期方式工作

:not选择器无法在jQuery中按预期方式工作