是否可以在并行进程上分配 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
是否可以在分隔符上拆分它(在本例中为===")并通过 stdin 将其提供给并行运行的命令?
Is it possible to split it on the delimiter (in this case '===') and feed it over stdin to a command running in parallel?
因此,上面的示例输入将导致 3 个并行进程(例如名为 do.sh 的命令),其中每个实例都接收到 STDIN 上的一部分数据,如下所示:
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)通过 STDIN 接收此信息:
foo
bar bar
baz
do.sh(实例 2)通过 STDIN 接收此信息:
qux
bla
do.sh(实例 3)通过 STDIN 接收:
def
zzz yyy
我认为使用 xargs 或 GNU 并行可以实现类似的功能,但我不知道如何实现.
I suppose something like this is possible using xargs or GNU parallel, but I do not know how.
推荐答案
GNU Parallel 从 20110205 版本开始可以做到这一点.
GNU Parallel can do that from version 20110205.
cat | parallel --pipe --recend '===
' --rrs do_stuff
这篇关于是否可以在并行进程上分配 STDIN?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!