From the sed manpage:
-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 situ- ations where disk space is exhausted, etc.
This doesn’t work:
sed -i -e's/apples/oranges/' file.txt
The key thing here is that the extension after the
-i flag is not optional. If you leave it off, sed assumes you’ll be entering it via stdin, which isn’t allowed and yields this error:
sed: -i may not be used with stdin
The solution is to send a zero-length extension like this:
sed -i '' -e's/apples/oranges/' file.txt
Careful with this, it could be really dangerous with poorly crafted commands.