我有这样的代码:
scan-codes | grep -i '[!]\| url:\|started\|Aborted' | grep -v 'Effective\|style\|WARNING\|The version' 输出:
[+] Started: Sat Feb 19 05:21:00 2022
| [!] 1 vulnerability identified:
| [!] Title: Cookie Notice & Compliance for GDPR / CCPA < 2.1.2 - Admin+ Stored Cross-Site Scripting
############## need break line here ##############
| [!] 1 vulnerability identified:
| [!] Title: WPBakery Page Builder < 6.4.1 - Authenticated Stored Cross-Site Scripting (XSS)
############## need break line here ##############
WARNING: Nokogiri was built against libxml version 2.9.10, but has dynamically loaded 2.9.12我想在grep后面放一条断线(比如\n)。这是扫描,所以我不能更改文件。
发布于 2022-02-20 00:01:54
建议使用单个awk脚本:
如果匹配合并了2个grep条件,则打印当前行+每2行换行:
awk '/\[!\]| url:|started|Aborted/ && !/Effective|style|WARNING|The version/ {ln++; print $0 (ln % 2) ? "\n": "";}'解释
/\[!\]| url:|started|Aborted/正线匹配条件!/Effective|style|WARNING|The version/负线匹配条件
{ # For each line passing all conditions
ln++; # count printed line
newLineMaker = (ln % 2) ? "\n": ""; # New line marker any 2nd line
print $0 newLineMaker; # print
}https://stackoverflow.com/questions/71184416
复制相似问题