This is a test version of Biostars. For the public version, visit https://www.biostars.org.
GNU parallel command with several multiple arguments

Dear all,

I am trying to use gnu parallel to run a command, where each command uses one from the first argument and two from the second. I've tried several things but without success.

I'd like to have something like:

parallel "command -t {1} {2} {3} > {1}_{2/..}.out " ::: 4 8 ::: File1 File2 File3 File4

and output:

command -t 4 File1 File2 > 4_File1.out
command -t 8 File1 File2 > 8_File1.out
command -t 4 File3 File4 > 4_File3.out
command -t 8 File3 File4 > 8_File3.out

Is it possible?

thanks,

parallel gnu parallel

2 answers

parallel --plus "command -t {1} {2} {3} > {1}_{2/..}.out " ::: 4 8 ::: File1 File3 :::+ File2 File4

I think arguments can be grouped by -N argument.

parallel --dry-run -N 2 command -t {1} {2} {4} {1}_{2}.out ::: 4 8 ::: File1 File2 File3 File4

thanks, that worked!

But can you explain a bit more the logic behind it? I tried using -N 2 but with {1} {2} {3}, and that did not work. Why does it work with {4}?

thanks

Sure. As per how I understand it, it is easiest to first print what gnuparallel sees and then cherrypick the argument numbers.

parallel --dry-run -N 2 command -t {} ::: 4 8 ::: File1 File2 File3 File4

will return

command -t 4 File1 4 File2
command -t 4 File3 4 File4
command -t 8 File1 8 File2
command -t 8 File3 8 File4

From these, the third one needs to be removed to generate the required command format so {1} {2} {4} and the output should be redirected to to a file which is {1}_{2}.out

nice trick. :) Thanks,

Log in to answer this question.