BSD sed: extra characters at the end of d command

For anyone who found this question due to a similar error message, but caused by an attempt to in-place edit on Mac OS X

As per https://github.com/lmquang/til/issues/18:

OS X requires the extension to be explicitly specified. The workaround is to set an empty string:

$ sed -i '' 's/megatron/pony/g' /path/to/file.txt

         ^^

man sed:

-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 partial content in situations where disk space is exhausted, etc.

So, there seems to be an issue on Mac OS X when extension is omitted, and so you have to supply -i with an empty string ('').

See also https://unix.stackexchange.com/a/112024/23614:

If using FreeBSD or OS/X, replace -i with -i ''.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)