Search code examples
gnu-parallel

GNU parallel: output each job to a different file without pipes


This question is very close to this other, but that answer is not valid for me, I think due to my shell script does not work with pipes.

This is my multi-job command :

parallel "./ClientesActivos-AP-N.sh -t 15" ::: $(seq 0 2)

I would like output to something like:

file0.out
file1.out
file2.out

I don't know where should I put the redirector >.

I have tested with no luck:

parallel ./ClientesActivos-AP-N.sh -t 15 ">" file{}.out ::: $(seq 0 1)
parallel ./ClientesActivos-AP-N.sh -t 15 ::: $(seq 0 1) ">" file{}.out

My script works in this way:

./ClientesActivos-AP-N.sh -t 15 0
./ClientesActivos-AP-N.sh -t 15 1
./ClientesActivos-AP-N.sh -t 15 2

So output would go (for the above manual unparallelized example) to file0.out, file1.out and file2.out.

What is the correct way to redirect each job to a different file?

Further unsuccessful tests:

parallel --files file{}.out "./ClientesActivos-AP-N.sh -t 15" ::: $(seq 0 2)

Solution

  • I find that the --dry-run option is a great way to debug GNU Parallel commands. Basically, it tells you what it would do without actually doing anything - it also saves me having to write a dummy "ClientesActivos" script and we all know how good my Spanish isn't ;-)

    So, to your immediate question, if you try this, I think what it shows is what you want to do:

    $ parallel --dry-run ./ClientesActivos-AP-N.sh -t 15 {} ">" file{}.out ::: {0..1}
    
    ./ClientesActivos-AP-N.sh -t 15 0 > file0.out
    ./ClientesActivos-AP-N.sh -t 15 1 > file1.out