Is it possible to distribute STDIN over parallel processes?

Posted by Erik on Stack Overflow See other posts from Stack Overflow or by Erik
Published on 2011-01-11T11:07:40Z Indexed on 2011/01/16 23:53 UTC
Read the original article Hit count: 456

Filed under:
|
|
|
|

Given the following example input on STDIN:

foo
bar bar
baz
===
qux
bla
===
def
zzz yyy

Is it possible to split it on the delimiter (in this case '===') and feed it over stdin to a command running in parallel?

So the example input above would result in 3 parallel processes (for example a command called do.sh) where each instance received a part of the data on STDIN, like this:

do.sh (instance 1) receives this over STDIN:

foo
bar bar
baz

do.sh (instance 2) receives this over STDIN:

qux
bla

do.sh (instance 3) receives this over STDIN:

def
zzz yyy

I suppose something like this is possible using xargs or GNU parallel, but I do not know how.

© Stack Overflow or respective owner

Related posts about bash

Related posts about processes