Sed替换返回错误

问题描述 投票:0回答:1
find ./ -type f -exec sed -i -e ’s/var\/www\/html/var\/www\/this_new_html/g’ {} \;

我试图运行上面的内容来替换所有具有以下内容的文件

include_once '/var/www/html/inc/functions.php';

include_once '/var/www/this_new_html/inc/functions.php';

我有很多包含行,所以使用批量替换sed替换会很好但是当我运行代码时

find ./ -type f -exec sed -i -e ’s/var\/www\/html/var\/www\/this_new_html/g’ {} \;

打印错误是

sed: -e expression #1, char 32: unknown option to `s'

如何更改以使其更换

bash sed quoting
1个回答
3
投票

不要使用,使用单引号'。另外,我建议在使用路径时使用不同的分隔符。使用#将显着提高可读性:

find . -type f -exec sed -i 's#var/www/html#var/www/this_new_html#g' {} +
© www.soinside.com 2019 - 2024. All rights reserved.