GNU parallel command with several multiple arguments
2
1
Entering edit mode
4.3 years ago
FGV ▴ 170

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 • 9.6k views
ADD COMMENT
3
Entering edit mode
4.3 years ago
ole.tange ★ 4.5k
parallel --plus "command -t {1} {2} {3} > {1}_{2/..}.out " ::: 4 8 ::: File1 File3 :::+ File2 File4
ADD COMMENT
2
Entering edit mode
4.3 years ago
microfuge ★ 1.9k

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

ADD COMMENT
0
Entering edit mode

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

ADD REPLY
2
Entering edit mode

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

ADD REPLY
0
Entering edit mode

nice trick. :) Thanks,

ADD REPLY

Login before adding your answer.

Traffic: 1903 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6