首页 > 解决方案 > 在 bash 的 sed 命令中使用感叹号

问题描述

我有一个像这样的文件,我想用sed.

// file.js
return foo.quux();

运行以下:

$ sed -i "s/foo\.(?!bar|baz)/qux\./g" file.js

预计文件将被替换,例如:

// file.js
return qux.quux();

bash一直告诉我:

bash: !bar: event not found

改写为:

$ sed -i "s/foo\.(?'!'bar|baz)/qux\./g" file.js

bash仍想为自己的目的使用感叹号:

bash: !: event not found

任何人都有关于如何在sedbash尝试参与的情况下制作排除的任何提示?

标签: regexbashsed

解决方案


推荐阅读