File editing with out creating a new file

I need edit some characters in a file, but without creating intermediatory file and also one liner.

I tried:

cat foo.txt | sed '/s/abc//g' > foo.txt
cat foo.txt | sed '/s/abc//g' >> foo.txt
 

First one is making foo.txt to zero byte, while second one is appending my desired output to existing content.

Actually I done have -i option in sed.

Any otherway to implement this ?

Thanks!

perl -i -pe 's/abc//g' foo.txt

karumudi7, that is useless use of cat. sed is capable of reading the file by itself.

Another way of doing it (without -i option):-

sed -e 's/abc//g' foo.txt > foo.tmp && mv foo.tmp foo.txt

Using ed:-

printf "%s\n" '1,$s/abc//g' w q | ed foo.txt
sed -i 's/this/that/g' foo

will do it

@grizzledtop: he already said in his first post that his sed doesn't have the "-i" flag. Only GNUs "sed" has this so its usage is strongly discouraged if you want to write portable scripts.

You might want to read this to understand why it is impossible.

I hope this helps.

bakunin