Use the -u
(--unbuffered
) option of sed, so it writes it's output, instead of collecting it first for a fast, large write later.
cat fifo | sed -u 's/a/b/' | sed -u 's/b/c/'
cat
is always unbuffered.
If it's not about sed
, but some program with output buffering, but without options to disable it, there are tools that can help to force buffering off - see man unbuffer
and man stdbuf
.
If it's a shell script, it should be unbuffered by default: when a command creates output in the script, and exits, the output is flushed. Otherwise, you use unbuffer inside the shell script.
For background, see this overview of stdio buffering.