Gnu parallel: how to build a command using the --link option to 'expand' positional arguments?

The problem

I'm using GNU parallel and want to pass two files to a program using the ::: operator. My directory tree looks like this:

$ ls 

SRR6301073_pass_1_trimmed.fq  
SRR6301073_pass_2_trimmed.fq  
SRR6301129_pass_1_trimmed.fq  
SRR6301129_pass_2_trimmed.fq  
...

The following code:

#!bin/bash
ones=$(find SRR*pass*1*.fq)
twos=$(find SRR*pass*2*.fq)    
parallel --link echo ::: $ones ::: $twos

Produces:

SRR6301033_pass_1_trimmed.fq SRR6301033_pass_2_trimmed.fq
SRR6301034_pass_1_trimmed.fq SRR6301034_pass_2_trimmed.fq
...

But I actually need the output to look like this:

-1 SRR6301033_pass_1_trimmed.fq -2 SRR6301033_pass_2_trimmed.fq
-1 SRR6301034_pass_1_trimmed.fq -2 SRR6301034_pass_2_trimmed.fq
...

What I've tried already

This:

$ parallel --link echo -1 ::: $ones -2 ::: $twos

produces

-1 SRR6301033_pass_1_trimmed.fq SRR6301033_pass_2_trimmed.fq
-1 SRR6301034_pass_1_trimmed.fq SRR6301034_pass_2_trimmed.fq

and this:

$ parallel --link echo -1 ::: $ones ::: $twos

Produces:

-1 SRR6301033_pass_1_trimmed.fq -2
-1 SRR6301034_pass_1_trimmed.fq SRR6301033_pass_2_trimmed.fq
-1 SRR6301037_pass_1_trimmed.fq SRR6301034_pass_2_trimmed.fq

1 answer

  • answered 2019-06-24 13:44 Mark Setchell

    I think you want this:

    parallel --dry-run --link echo -1 {1} -2 {2} ::: a b ::: c d
    

    Output

    echo -1 a -2 c
    echo -1 b -2 d