如何捕获XTH模式1到模式2
这是我解释我的问题的示例:
Bug Day 2022-01-13:
Security-Fail 248975
Resolve:
...
Bug Day 2022-01-25:
Security-Fail 225489
Security-Fail 225256
Security-Fail 225236
Resolve:
...
Bug Day 2022-02-02:
Security-Fail 222599
Resolve:
因此,我有一个包含多个安全漏洞的大文件。 我想获得这一点:
2022-01-13;248975
2022-01-25;225489,225256,225236
2022-02-02;222599
我要做类似
bugDayNb=$(grep "Bug Day" | wc -l)
for i in $bugDayNb; do
echo "myBugsFile" | grep -A10 -m$i "Bug Day"
done
此命令的问题是,如果有10个以上的安全性失效,它将行不通,如果我放置“ -a50”,它可能会采取下一个安全性 - 下一个错误日。
因此,我希望一种方法 sed 或类似的东西,从xth“ bug day”到xth“ resolve”
谢谢!
this is my example to explain my question :
Bug Day 2022-01-13:
Security-Fail 248975
Resolve:
...
Bug Day 2022-01-25:
Security-Fail 225489
Security-Fail 225256
Security-Fail 225236
Resolve:
...
Bug Day 2022-02-02:
Security-Fail 222599
Resolve:
So, I have a big file that contain multiple security vulnerabilities.
I want to obtain that :
2022-01-13;248975
2022-01-25;225489,225256,225236
2022-02-02;222599
I though about doing something like
bugDayNb=$(grep "Bug Day" | wc -l)
for i in $bugDayNb; do
echo "myBugsFile" | grep -A10 -m$i "Bug Day"
done
The problem of this command is, if there are more than 10 Security-Fail, it won't works, and if I put a "-A50" it may take the next Security-Fail of the next Bug Day.
So I would prefer a way to sed or something like that from xth "Bug Day" to xth "Resolve"
Thank you !!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是一种方法:
/^bug Day/{d = $ nf; s =“”}
将日期保存到变量d
如果行以bug Day
开始,然后初始化s
到空字符串{d = $ nf; sub(/:$/,“;”,d); s =“”}
如果要;
而不是:/^security-fail/{d = d = ds $ nf; s =“,”}
当行以Security-Fail
将数字附加到d
变量并设置S
时,以便进一步附录将通过,
/^分离:/{print D}
在resolve:
时打印结果。Here's one way to do it:
/^Bug Day/{d=$NF; s=""}
save the date to variabled
if line starts withBug Day
and initializes
to empty string{d=$NF; sub(/:$/, ";", d); s=""}
if you want;
instead of:
/^Security-Fail/{d = d s $NF; s=","}
when line starts withSecurity-Fail
append the number tod
variable and sets
so that further appends will be separated by,
/^Resolve:/{print d}
print the results whenResolve:
is seen使用您显示的样本,请尝试以下内容
AWK
程序。说明: 添加了上述详细说明。
With your shown samples, please try following
awk
program.Explanation: Adding detailed explanation for above.
这可能对您有用(gnu sed):
在
bug Day
和resolve
和格式相应地收集行。如果您想对一天或几天的选择有选择性,请使用:
以上命令显示前3天IE 1至3
This might work for you (GNU sed):
Gather up lines between
Bug Day
andResolve
and format accordingly.If you want to be selective about a single day or range of days, use:
The above command displays the first 3 days i.e. 1 to 3
您能尝试尝试
awk
解决方案:如果您喜欢单线:
Would you please try an
awk
solution:If you prefer a one-liner: