Search code examples
gnu-parallel

GNU Parallel: how to pass job id to command


Suppose I am running gnu parallel on an array of items received from standard in, and split according to some criteria:

cat content | parallel -j 4 my_command

How do I access the job number such that I can pass into command, as an argument, the job number/id of the parallel execution (so that each parallel execution block has a unique number):

cat content | parallel -j 4 my_command -n ???

(Is this even possible? Reviewing the man pages at the moment)


Solution

  • You are looking for the replacement string {#}

    cat content | parallel -j 4 my_command -n {#}
    

    It is also mentioned on the cheat sheet: https://www.gnu.org/software/parallel/parallel_cheat.pdf