Possible Duplicate:
How can I make iconv replace the input file with the converted output?
I frequently connect to amazon ec2 using their public DNS names
(ec2-12-34-56-78.compute-1.amazonaws.com
) and because of this my known_hosts
file gets overwhelmed with a lot of ec2
entries I will never use again.
I know I could probably use sed -i
to edit in place but I wanted to use grep
and so I did this:
grep -v ec2 ~/.ssh/known_hosts > ~/.ssh/known_hosts
That leaves known_hosts
as an empty file. If I do:
grep -v ec2 ~/.ssh/known_hosts > ~/.ssh/tmp
mv ~/.ssh/tmp ~/.ssh/known_hosts
then things are fine, but I am confused why reading and writing to the same file leaves it blank, and if there is any way around this when using grep
, cat
, etc.
grep
would not have a chance to do anything about it anyway). I'm just confused as to how it would be expected to work in the first place. – geekosaur Apr 11 '12 at 20:00COMMAND.COM
and so had the overwrite happen before the command even ran. – geekosaur Apr 11 '12 at 20:38sponge
then :) – cwd Apr 11 '12 at 21:37sed -i /ec2/d
? – ephemient Apr 11 '12 at 22:49