This works
head -c 10 /dev/zero | sed 's/\x0/x/g'
and generates xxxxxxxxxx as expected.
Then I tried this:
sed 's/\x0/x/g' /dev/zero | head -c 10
which seems to just hang.
Then I thought, oh, sure, there's no newline in here and sed can't even finish take a line in the pattern space, so it hangs. Is that the reason why the command above hangs?
But wait, there's a -u option:
-u, --unbuffered load minimal amounts of data from the input files and flush the output buffers more often
which made me think it would be the solution, but it also seems to block:
sed -u 's/\x0/x/g' /dev/zero | head -c 10
Does this mean that it is just not possible to operate with sed on an infinite stream?
/dev/zerois like/dev/null: there's no output from this.null, zero - data sinkWhat are tou trying to achieve with/dev/zeroat the beginning?/dev/zerocan be used as an infinite source (which I think the first snippet shows), wheras/dev/nullcan't. What am I trying to achive? Nothing but understanding. The question popped to my mind when I tried usingcat /dev/zeroas something that doesn't return./dev/zeroproduces an endless stream of zero/NUL bytes\x00. Reading from/dev/nullproduces just a zero-length read, an "EOF".dd if=/dev/zero of=/dev/sdX. But what I don't get is why this don't work? :cat /dev/zero | headheadwithout any arguments behaves likehead -n 10, i.e., prints the first 10 lines./dev/zeroproduces an infinite string ofNULoctets, and never produces a line terminator. In other words, it produces a single infinite line ofNULbytes. Since you askedheadto print the first 10 lines, it will need to wait for the tenth line terminator … which never comes. See pubs.opengroup.org/onlinepubs/9799919799 for details.