For the benefit of anyone googling thisthe question "how do I modify a file in-place?", the correct answer in the usual case is stop looking for obscure shell features that risk corrupting your file for negligible performance gain, and instead use some variation of this pattern:
grep "foo" file > file.new && mv file.new file
Only in the extremely uncommon situation that this is for some reason not feasible, should you seriously consider any of the other answers on this page (although they are certainly interesting to read). I will concede that the OP's conundrum of having no disk space to create a second file is exactly such a situation. Although even then, there are other options available, e.g. as provided by @Ed Randall and @Basile Starynkevitch.