GNU parallel to variable sequence?

I want to run the prog program in parallel using GNU parallel with an argument that takes a value in sequence. For instance:

 parallel prog ::: {1..100} 

However, I do not know the upper bound of the sequence in advance, so I would like to do something like:

 parallel prog ::: {1..$x} 

where $x is the number I will calculate somewhere. How can I achieve this?

+6
source share
1 answer

Assuming the seq program (or something like that) is available,

 parallel prog ::: $(seq 1 $x) 

If not, you can fake it:

 parallel prog ::: $(for ((i=1; i < x; i++)) do; echo $i; done) 

As Ole points out, if $x large, then the resulting sequence of numbers may be too large to fit on the command line. In this case, use one of the two methods above to supply arguments to parallel through standard input:

 seq 1 "$x" | parallel prog for ((i=1; i<x; i++)) do; echo "$i"; done | parallel prog 
+5
source

Source: https://habr.com/ru/post/988476/


All Articles