Search code examples
gnu-parallel

How do I get all input args combined without redundancy?


I want to get all combinations without replacement for args (files) A, B and C.

That is I want to get the combinations

A B
B C
A C

without redundant ones like B A.

Is it possible to do that easily with GNU parallel?

My current command looks like:

 parallel 'echo {1} {2}' ::: (ls *txt) ::: (ls *txt)

but this prints all combos.

Ps. there are many more files than three, so general solutions only please.


Solution

  • There is no elegant solution:

    parallel 'test "{1}" \< "{2}" && echo {1} {2}' ::: *txt ::: *txt
    

    From version 20170922 you can do:

    $ parallel --plus echo {choose_k} ::: a b c ::: a b c
    a b
    a c
    b c