Home > Blockchain >  Output of sed is cut off early when piped to tee
Output of sed is cut off early when piped to tee

Time:05-13

I expect that:

  1. cat file.txt | sed s/a/b/ > /tmp/tmp.txt && sudo cp /tmp/tmp.txt file.txt

and

  1. 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.

  • Related