|
|
|
|
|
by jpab
2124 days ago
|
|
The purpose of sponge is that you can do this: grep foo file.txt | sponge file.txt If you do this with redirections then file.txt will be truncated before it's been processed, leaving you with an empty file instead of what you wanted. Sponge collects its input first and then writes everything out at the end, so you can output to a file that was used as an input. (Parent updated while I was writing. Oh well) |
|
Commands that process file in place (sed -i) write to a temporary file in the same filesystem and then rename to the target file, which works if you want to process files that don't fit into memory.