mac下用sed报错 command c expects \ followed by text

一条很简单的替换文本的命令:

sed -i 's/www.a.cn/www.b.com/g' common.js,报错command c expects \ followed by text

但是同样的命令在服务器上是可以正确执行的,看了mac下的man sed,里面-i选项中的解释:

     Edit files in-place, saving backups with the specified extension.

             If a zero-length extension is given, no backup will be saved.  It

             is not recommended to give a zero-length extension when in-place

             editing files, as you risk corruption or partial content in situ-

             ations where disk space is exhausted, etc.

大概的意思就是说用-i的选项时mac会进行强制备份,所以你必须给出一个后缀名进行备份,如果你不想进行备份,直接用空字符即可

sed -i '' 's/www.a.cn/www.b.com/g' common.js

posted @ 2016-10-12 15:01  迷藏马甲  阅读(6765)  评论(0编辑  收藏  举报