Re:A collection of Unix terminal/console/curses tools
by wging on Friday February 28, 2014 @11:50PM
(#7323135)
How is sponge different from > filename?
[ Parent
| on HN ]
Re:A collection of Unix terminal/console/curses tools
by tmhedberg on Saturday March 01, 2014 @12:26AM
(#7323242)
For one thing, it allows your pipeline to both read from and write to the same file, as it defers the output until there is no more data to read from "upstream". For instance, this won't work (it truncates the file for writing before it is ever read):
grep foo <some_file >some_file
But this will have the intended effect: grep foo <some_file | sponge some_file
Re:A collection of Unix terminal/console/curses tools
by loevborg on Saturday March 01, 2014 @01:17PM
(#7325380)
It can be used where ">" does not work, e.g. when using sudo. So you can do
echo data | sudo sponge /etc/a.file
`tee` can be abused in a similar way, but it also prints the data to stdout, which is ugly.