I would like to use the same pipe for different applications, like in:
cat my_file | {
cmd1
cmd2
cmd3
}
Cmd1 should consume part of the input. Cmd2 should consume another part and so on.
However, each cmd eats more of the input then it read really needs due buffering.
For example:
yes | nl | {
head -n 10 > /dev/null
cat
} | head -n 10
Outputs from line 912 instead of line 11.
Tee is not a good option, because each command is supposed to consume part of the stdin.
Is there a simple way to get this working?
Best Answer
You may use
tee
to duplicate command for processing whole stream by many command:or split line by line, using bash:
Finaly there is a way for running
cmd1
,cmd2
andcmd3
only once with 1/3 of stream as STDIN:For trying this, you could use:
For using one stream on different process if on same script, you could do:
For this, you may have to transform your separated scripts into bash function to be able to build one overall script.
Another way could be to ensure each script won't output anything to STDOUT, than add a
cat
at end of each script to be able to chain them:Final command could look like: