nextflow: Filter outputs of a process
Instead of outputting all files and filtering for only bim, output only bims:
output:
tuple val(&quot;${prefix}&quot;), path(&quot;${prefix}.{bed,bim,fam}&quot;) into (step1a_out,step1a_bim)

Do
output:
tuple val(&quot;${prefix}&quot;), path(&quot;${prefix}.{bed,bim,fam}&quot;) into step1a_out
tuple val(&quot;${prefix}&quot;), path(&quot;${prefix}.bim&quot;) into step1a_bim

So you can skip your complicated filter:
process step1b {
    input:
    tuple val(bim), path(bimfile) from step1a_bim
    output:
    path(&quot;${prefix}.step1b.snplist.txt")
tuple val("${sample_name}&quot;), path(&quot;${sample_name}.step1c.{bed,bim,fam}") into 
step1b_results
    script:
    """
    awk '{ if ((\\\\\$5=="T" &amp;&amp; \\\\\$6=="A")||(\\\\\$5=="A" &amp;&amp; \\\\\$6=="T")||(\\\\\$5=="C" &amp;&amp; \\\\\$6=="G")||(\\\\\$5=="G" &amp;&amp; \\\\\$6=="C")) print \\\\\$2, "ambig" ; else print \\\\\$2 ;}' "$bimfile&quot; | grep ambig &gt; &quot;${prefix}.step1b.snplist.txt"
    plink --bfile "${prefix}.step1b&quot; --exclude &quot;${prefix}.step1b.snplist.txt" --make-bed --out "${prefix}.step1c&quot;

&quot;&quot;&quot;

```