shell sed命令匹配模式并替换它[复制]

rjzwgtxy  于 2023-05-29  发布在  Shell
关注(0)|答案(1)|浏览(166)

此问题已在此处有答案

sed: Replace part of a line(7个回答)
5天前关闭。
我想使用sed命令将日志中的敏感信息替换为****。其中一个日志如下所示:

"Log: abcservice : dataUsername generated is = QWE000387769@as.bbi.co\n","stream":"stdout""

我想要的输出是:

"Log: abcservice : dataUsername generated is = ******@as.bbi.co\n","stream":"stdout""

我试过:

sed 's#"dataUsername generated is [a-zA-ZO-9@.-]"#"dataUsername generated is = ******"#g"

如何匹配模式“dataUsername generated is = QWE000387769@as.bbi.co“并将其替换为“dataUsername generated is =******@as.bbi.co\n”

jmo0nnb3

jmo0nnb31#

使用sed

$ sed -E 's/(dataUsername generated is = )[^@]*/\1******/' input_file
"Log: abcservice : dataUsername generated is = ******@as.bbi.co\n","stream":"stdout""

相关问题