somecmd < somefile | othercmd | anothercmd > somefile
Sponge "soaks up" all the output before writing any of it, so that you can write pipelines like that:
somecmd < somefile | othercmd | anothercmd | sponge somefile
$ cat foo foo bar baz $ ( rm foo && grep ba > foo ) < foo $ cat foo bar baz $