I\'m writing a application that acts like a filter: it reads input from a file (stdin), processes, and write output to another file (stdout). The input file is completely re
There's a sponge utility in moreutils package:
./myprog < file.txt | sponge file.txt
To quote the manual:
Sponge reads standard input and writes it out to the specified file. Unlike a shell redirect, sponge soaks up all its input before opening the output file. This allows constructing pipelines that read from and write to the same file.