我想分别提取每个###
之间的文本,以与不同的文件进行比较。需要提取所有docker图像的所有CVE
编号,以与以前的报告进行比较。文件如下所示。这是一个片段,它有超过100行这样的。需要通过Shell脚本来完成此操作。敬请帮助。
### Vulnerabilities found in docker image alarm-integrator:22.0.0-150
| CVE | X-ray Severity | Anchore Severity | Trivy Severity | TR |
| :--- | :------------: | :--------------: | :------------: | :--- |
|[CVE-2020-29361](#221fbde4e2e4f3dd920622768262ee64c52d1e1384da790c4ba997ce4383925e)|||Important|
|[CVE-2021-35515](#898e82a9a616cf44385ca288fc73518c0a6a20c5e0aae74ed8cf4db9e36f25ce)|||High|
### Vulnerabilities found in docker image br-agent:22.0.0-154
| CVE | X-ray Severity | Anchore Severity | Trivy Severity | TR |
| :--- | :------------: | :--------------: | :------------: | :--- |
|[CVE-2020-29361](#221fbde4e2e4f3dd920622768262ee64c52d1e1384da790c4ba997ce4383925e)|||Important|
|[CVE-2021-23214](#75eaa96ec256afa7bc6bc3445bab2e7c5a5750678b7cda792e3c690667eacd98)|||Important|
我试过类似grep -oP '(?<=\"##\").*?(?=\"##\")'
的东西,但它不工作。
预期输出:
For alarm-integrator
CVE-2020-29361
CVE-2021-35515
For br-agent
CVE-2020-29361
CVE-2021-23214
3条答案
按热度按时间fkaflof61#
请使用所示示例尝试以下
awk
代码***说明:***增加上述
awk
代码的详细说明。bpzcxfmw2#
使用GNU awk(我假设您已经有了或者可以得到,因为您使用的是GNU grep),将第三个参数与match()匹配:
mxg2im7a3#
使用
awk
可以执行以下操作:FS
配置为|[[]|[]]
:空格、[
字符或]
字符。For alarm-integrator
和For br-agent
all CVE numbers
的操作可读性更强: