3 ms·
Maybe I'm missing it, but this doesn't seem applicable to what my sponge program (and joeyh's) are intended to do: to modify a file "in-place". joeyh's example
by graue 14y ago
Maybe I'm missing it, but this doesn't seem applicable to what my sponge program (and joeyh's) are intended to do: to modify a file "in-place".
joeyh's example:
sed "s/root/toor/" /etc/passwd | grep -v joey | sponge /etc/passwd
My example:
sort <foo | sponge foo
- lutusp 14y agoThe whole point of a pipe is to have concurrent input and output. If so, and if you open the same file for input and output, you risk erasing the file by opening and deleting the file on the output side before reading it on the input side. If the pipe is an unfulfilled promise (no concurrency) then there's no problem. But if the pipe does what it's designed to do, you will lose the file.
- frio 14y agoMaybe in my quest to be a smartarse, I'm the one missing it... but why can't you just use > in both those cases? EDIT -- after tinkering around with the console, I see. I'm wiping the file out by writing to it (>) before it's finished reading (<). Neat, TIL!
- oijaf888 14y agoCouldn't you just use 'tee'? whatever <file | tee file 1>/dev/null
- graue 14y agoOh, cool. That does seem to work, when using GNU coreutils. So either: 1. I never thought to try that. How silly of me. OR 2. Perhaps tee behaves differently on OpenBSD (which I was using at the time).