Search code examples
gnugnu-parallel

rename output files with iteration number and input with gnu parallel


I have a list of files (data1.txt, ... ,data6.txt) and I want to run the same commands on them 3 times as example. I am using gnu parallel

I want as output files: 1data1.txt, 2data1.txt, 3data1.txt, ... , 2data6.txt, 3data6.txt.

I tried:

for i in $(seq 3); do parallel -j 8 'myCommand data{}.txt > results/out/{$i}data{}.txt' ::: 1 2 3 4 5 6; done

but my output files are : {}data1.txt, ...., {}data6.txt

I've tried different possibilities but I don't have the expected results


Solution

  • Use GNU Parallel's feature of making combinations:

    parallel -j 8 myCommand data{2}.txt '>' results/out/{1}data{2}.txt' ::: 1 2 3 ::: 1 2 3 4 5 6
    

    If your CPU has 8 threads you can leave out -j8. This is a good idea, if you later are going to run it on a bigger system.

    You can also use --results (requires version >20170222):

    parallel --results results/out/{1}data{2}.txt myCommand data{2}.txt ::: 1 2 3 ::: 1 2 3 4 5 6 >/dev/null