sed: 1: "xxxxx": extra characters at the end of g command----sed on mac

1、场景:

在mac上,使用sed命令把当前目录的test.sql文件内容中的a替换为b,使用命令:sed -i “s/a/b/g” test.sql

遇到报错:sed: 1: “grep …”: extra characters at the end of g command

2、解决:

在mac中使用sed命令在-i参数后面需要带一对双引号"",正确格式如下:

sed -i “” “s/a/b/g” test.sql

3、原因

sed -i 后面的双引号中可写任意字符串或者为空,含义是用于生成源文件的备份文件的文件名。比如上面的例子:sed -i “_tmp” “s/a/b/g” test.sql,在替换test.sql的同时,还会生成test.sql_tmp的备份文件

你可能感兴趣的:(Shell,--Mac)