3 ms·
sponge buffers the whole input before writing the output. Its utility would be in reading from a file, working on it with other tools, and writing the result ba
by pepve 6y ago
sponge buffers the whole input before writing the output. Its utility would be in reading from a file, working on it with other tools, and writing the result back to the original file, all in one line.
- kyran_adept 6y agoI know I wanted to do this, but I am very happy such a utility doesn't exist. Unix utilities, usually work in a pipeline fashion, read line -> process -> write to output. This allows them to allocate a limited amount of memory. If you read all input in memory, you are asking for trouble: 'cat /dev/zero | sponge a'.
- FeepingCreature 6y agoThat is the point.
- zeroimpl 6y agoI routinely operate on machines with gigabytes of memory, but rarely write pipelines which output gigabytes of data, so this has never been a concern for me. But even then, there’s still swap space which is effectively like using a temp file but lazier. By the way, I think you’d be in even more trouble if you wrote: cat /dev/zero > a
- thomashabets2 6y agoOh, neat! Thanks.
- thomashabets2 6y agoSeems like the example command should be easily doable with just `sed -i`, though. sed -i 's/root/toor/;/joey/d' /etc/passwd But I get your point.