How to run parallel with increment multiplication

I know that I can use "parallel" to run multiple instances of any script / application in parallel on a variable with a given increment, for example:

parallel "echo hello {}" ::: {1..16..2}

Conclusion:

hello 1
hello 3
hello 5
hello 7
hello 9
hello 11
hello 13
hello 15

I want to use an increment that multiplies the run variable so that I get this output:

hello 1
hello 2
hello 4
hello 8
hello 16

What should I write in {1..16 .. #}?

Thank!

+4
source share
2 answers

Try the following:

parallel "echo hello {}" ::: $(awk 'BEGIN {for(i=0; i<=16; i++) printf 2**i" "}')

awkused to print a list of degrees 2, which will then be used parallel.

As an alternative:

parallel "echo hello {}" ::: $(printf '%s\n' 2^{0..16} | bc | tr '\n' ' ')

1 16 x^2, printf, . bc , tr .

+1

{= =} ( 20140822 ):

seq 1 2 16 | parallel echo hello {}
parallel echo hello '{= $_=2*$_ =}' ::: {1..16}
seq 1 16 | parallel echo hello '{= $_=2**$_ =}'
parallel echo hello '{= $_=2**$_ =}'  ::: {1..16}
+1

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


All Articles