sponge rules, but you need to be careful. Lets say you wanted to search/replace a file with sed and sponge, then this does not work:
cat file.txt | sed "s/a/b/g" | sponge > file.txt
Because bash opens file.txt for writing and truncates it
immediately, so "cat file.txt" wont output anything. You have to do this for it to work: cat file.txt | sed "s/a/b/g" | sponge file.txt
sponge wont open the file for writing until it's sponged everything up. If you remember this, sponge is an awesome tool in the UNIX toolbox.