I expect that:
cat file.txt | sed s/a/b/ > /tmp/tmp.txt && sudo cp /tmp/tmp.txt file.txt
and
cat file.txt | sed s/a/b/ | sudo tee file.txt > /dev/null
produce the same result in file.txt
but for some reason when file.txt
is quite big (see 10 000 000 bytes) the resulting write of file.txt
is cut off at 262 144 bytes with the second snippet (2).
I expect some sort of buffering is at play here, but I would expect the second snippet to work. Or am I mistaken in how pipes, cat
, sed
, and tee
work?
The idea is that file.txt
is root owned and thus I need to sudo the tee
command to be able to write back to that location.
CodePudding user response:
This is a duplicate question.
Answered here, and here. In different forum.
The answer is to use command unbuffer
or stdbuf
which ever you have installed.