Moreutils: A collection of Unix tools that nobody thought to write long ago
I find sponge really useful. Have you ever wanted to process a file through a pipeline and write the output back to the file? If you do it the naive way, it won’t work, and you’ll end up losing the contents of your file:<p><pre><code>    awk '{do_stuff()}' myfile.txt | sort -u | column --table > myfile.txt
</code></pre>
The shell will truncate myfile.txt before awk (or whatever command) has a chance to read it. So you can use sponge instead, which waits until it reads EOF to truncate/write the file.<p><pre><code>    awk '{do_stuff()}' myfile.txt | sort -u | column --table | sponge myfile.txt</code></pre>