Redirect output from sed 's/c/d/' myFile to myFile

Posted by sixtyfootersdude on Stack Overflow See other posts from Stack Overflow or by sixtyfootersdude
Published on 2010-04-06T14:13:48Z Indexed on 2010/04/06 14:23 UTC
Read the original article Hit count: 216

Filed under:
|
|
|

I am using sed in a script to do a replace and I want to have the replaced file overwrite the file. Normally I think that you would use this:

% sed -i 's/cat/dog/' manipulate
sed: illegal option -- i

However as you can see my sed does not have that command.

I tried this:

% sed 's/cat/dog/' manipulate > manipulate

But this just turns manipulate into an empty file (makes sense).

This works:

% sed 's/cat/dog/' manipulate > tmp; mv tmp manipulate

But I was wondering if there was a standard way to redirect output into the same file that input was taken from.

© Stack Overflow or respective owner

Related posts about redirection

Related posts about bash