Suppose I have the following command in bash:
one | two
one
runs for a long time producing a stream of output and two
performs a quick operation on each line of that stream, but two
doesn't work at all unless the first value it reads tells it how many values to read per line. one
does not output that value, but I know what it is in advance (let's say it's 15
). I want to send a 15\n
through the pipe before the output of one
. I do not want to modify one
or two
.
My first thought was to do:
echo "$(echo 15; one)" | two
That gives me the correct output, but it doesn't stream through the pipe at all until the command one
finishes. I want the output to start streaming right away through the pipe, since it takes a long time to execute (months).
I also tried:
echo 15; one | two
Which, of course, outputs 15, but doesn't send it through the pipe to two
.
Is there a way in bash to pass '15\n' through the pipe and then start streaming the output of one
through the same pipe?
{ echo 15; one; } | two
– Atalya