Tag Archives: sed

How to Solve Mac Sed Error: command c expects followed by text

A very simple command to replace text:

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

Command C expectations following by text
may also report invalid command code W

But the same command can be executed correctly on the server. See the explanation in the – I option of man sed under Mac

-i extension
             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 par-
             tial content in situations where disk space is exhausted, etc.

The general meaning is that Mac will force backup when using – I option, so you must give a suffix to backup. If you don’t want to backup, you can use empty character directly

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