shell 使用sed时排除特定模式

atmip9wb  于 2023-03-24  发布在  Shell
关注(0)|答案(2)|浏览(129)

我需要问一个问题,如果这可能与sed实用程序。我有文件(只是一块- 2行):

"740b3d39-7676-485a-b3d6-041f6af273e5"|"8917963"|"BDSA-2021-3803"|"CVE-2021-4102"|"BDSA"|"NEW"|""|""|""|"Chromium is vulnerable to a use-after-free (UAF) issue in the `V8` functionality.A remote attacker could trick a victim user into viewing a crafted HTML page in order to trigger the UAF flaw and cause memory corruption.**Note**: Google has reported [here](https://chromereleases.googleblog.com/2021/12/stable-channel-update-for-desktop_13.html) that they are ""aware of reports that an exploit for CVE-2021-4102 exists in the wild.""
This vulnerability is listed as exploitable by the Cybersecurity & Infrastructure Security Agency in their [Known Exploited Vulnerabilities Catalog](https://www.cisa.gov/known-exploited-vulnerabilities-catalog)."|"MEDIUM"|"6.8"|"8.6"|"6.4"|""|"HIGH"|"8.8"|"2.8"|"5.9"|"8.2"|"NETWORK"|"True"|"False"|"2021-12-17 12:59:04.779000+00:00"|"2022-12-13 14:15:49.529000+00:00"|""|""

我想用任何字符替换""(例如~),但仍保留|""我试图运行sed "/\|\"\"/ s/\"\"/~/g",但这将全部替换到文件中,我只需要""的引用
请指教,并感谢愿意帮助

sed "/\|\"\"/ s/\"\"/~/g"  <file_name>
8ulbf1ek

8ulbf1ek1#

这就是你要做的吗,在搜索和替换部分使用接受\n的sed,例如GNU sed?

$ sed 's/|""/\n/g; s/""/~/g; s/\n/|""/g' file
"740b3d39-7676-485a-b3d6-041f6af273e5"|"8917963"|"BDSA-2021-3803"|"CVE-2021-4102"|"BDSA"|"NEW"|""|""|""|"Chromium is vulnerable to a use-after-free (UAF) issue in the `V8` functionality.A remote attacker could trick a victim user into viewing a crafted HTML page in order to trigger the UAF flaw and cause memory corruption.**Note**: Google has reported [here](https://chromereleases.googleblog.com/2021/12/stable-channel-update-for-desktop_13.html) that they are ~aware of reports that an exploit for CVE-2021-4102 exists in the wild.~
This vulnerability is listed as exploitable by the Cybersecurity & Infrastructure Security Agency in their [Known Exploited Vulnerabilities Catalog](https://www.cisa.gov/known-exploited-vulnerabilities-catalog)."|"MEDIUM"|"6.8"|"8.6"|"6.4"|""|"HIGH"|"8.8"|"2.8"|"5.9"|"8.2"|"NETWORK"|"True"|"False"|"2021-12-17 12:59:04.779000+00:00"|"2022-12-13 14:15:49.529000+00:00"|""|""

对于其他sed,您可以将\n替换为反斜杠,后跟文字换行符或'$'\n''或类似内容。

1l5u6lss

1l5u6lss2#

例如在are ""awarewild.""中替换"",但不替换|""

$ sed -E 's/([^|])""/\1~/g' file

相关问题