使用 GNU 并行分割命令行参数
使用GNU并行
:http://www.gnu.org/software/parallel /
我有一个需要两个参数的程序,例如
$ ./prog file1 file2
$ ./prog file2 file3
...
$ ./prog file23456 file23457
我正在使用生成文件名对的脚本,但这会带来问题,因为脚本的结果是单个字符串 - 而不是一对。像:
$ ./prog "file1 file2"
GNU并行似乎有很多技巧,我想知道是否有一个用于围绕分隔符分割文本的技巧:
$ generate_file_pairs | parallel ./prog ?
# where ? is text under consideration, like "file1 file2"
简单的解决方法是在prog中手动分割参数,但我会想知道 GNU 并行是否可能。
Using GNU parallel
: http://www.gnu.org/software/parallel/
I have a program that takes two arguments, e.g.
$ ./prog file1 file2
$ ./prog file2 file3
...
$ ./prog file23456 file23457
I'm using a script that generates the file name pairs, however this poses a problem because the result of the script is a single string - not a pair. like:
$ ./prog "file1 file2"
GNU parallel
seems to have a slew of tricks up its sleeves, I wonder if there's one for splitting text around separators:
$ generate_file_pairs | parallel ./prog ?
# where ? is text under consideration, like "file1 file2"
The easy work around is to split the args manually in prog, but I'd like to know if it's possible in GNU parallel
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可能正在寻找
--colsep
。阅读
manparallel
了解更多信息。如果您还没有观看介绍视频,请观看http://www.youtube.com/watch?v=OpaiGYxkSuQ< /a>You are probably looking for
--colsep
.Read
man parallel
for more. And watch the intro video if you have not already done so http://www.youtube.com/watch?v=OpaiGYxkSuQ很晚了,但我经常遇到这个问题,并找到了一个很好的简单解决方案,
在将 arg 列表传递给并行之前,只需用换行符替换所有空格即可。我发现
tr
对于此类内容来说是最快的不工作
工作
Protip:早于 实际上运行并行命令时,我做了两件事来检查参数是否已正确分割。
echo
。这意味着最终将执行的任何命令都将被打印出来供您首先检查>请注意,这对于小/中参数列表最有效。如果参数列表非常大,可能最好只使用 for 循环来回显每个参数以并行
Quite late to the party here, but I bump into this problem fairly often and found a nice easy solution
Before passing the arg list to parallel, just replace all the spaces with newlines. I've found
tr
to be the fastest for this kind of stuffNot working
Working
Protip: before actually running the parallel command, I do 2 things to check that the arguments have been split correctly.
echo
in front of your bash command. This means that any commands that will eventually be executed will be printed for you to check first> Note, this works best with small/medium argument lists. If the argument list is very large, probably best to just use a for loop to echo each argument to parallel
您正在寻找并行的
-n
选项。这就是您要查找的内容:摘自 GNU 并行文档:
You are looking for
-n
option of parallel. This is what you are looking for:Excerpt from GNU Parallel Doc:
Parallel 的手册中说:
因此,尝试一下:
尝试理解以下输出:
In Parallel's manual, it is said:
So take a try of:
Try to understand the output of this: