Issue
I know GNU Parallel is amazing at munching through all combinations of input parameters. I however have a script where I want the opposite, I have multiple arrays which I want to combine using a simple index.
This is what I have:
#!/bin/bash
letters='a b'
numbers='1 2'
f1(){
echo $1 $2
echo letter: $1
echo number: $2
}
export -f f1
parallel f1 {1} {2} ::: $letters ::: $numbers
which gives:
a 1
letter: a
number: 1
a 2
letter: a
number: 2
b 1
letter: b
number: 1
b 2
letter: b
number: 2
I would just want to have this result though:
a 1
letter: a
number: 1
b 2
letter: b
number: 2
Any help appreciated, I didn't find an index switch in the (long) docs.
Solution
I think you just want to "link" your arguments:
parallel --link echo {1} {2} ::: 1 2 3 ::: a b c
Output
1 a
2 b
3 c
As opposed to:
parallel echo {1} {2} ::: 1 2 3 ::: a b c
which produces all permutations:
1 a
1 b
1 c
2 a
2 b
2 c
3 a
3 b
3 c
Answered By - Mark Setchell Answer Checked By - Timothy Miller (WPSolving Admin)