是否有可能超过并行进程分配STDIN? [英] Is it possible to distribute STDIN over parallel processes?
问题描述
鉴于STDIN下面的示例中输入:
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?
因此,例如输入以上将导致在每个实例收到STDIN数据的一部分,像这样3个平行处理(例如命令调用do.sh):
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(比如1)收到此标准输入:的
foo
bar bar
baz
的 do.sh(例如2)接收该标准输入:的
qux
bla
的 do.sh(例如3)接收该标准输入:的
def
zzz yyy
我想这样的事情是可以使用的xargs或GNU平行的,但我不知道怎么办。
I suppose something like this is possible using xargs or GNU parallel, but I do not know how.
推荐答案
GNU并行能做到这一点从版本20110205。
GNU Parallel can do that from version 20110205.
cat | parallel --pipe --recend '===\n' --rrs do_stuff
这篇关于是否有可能超过并行进程分配STDIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!