I know that I can use "parallel" to run multiple instances of whatever script/application in parallel over a variable with a given increment, eg:
parallel "echo hello {}" ::: {1..16..2}
Output would be:
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 an output like this:
hello 1
hello 2
hello 4
hello 8
hello 16
What should I write in the {1..16..#}?
Thanks!
Try this:
parallel "echo hello {}" ::: $(awk 'BEGIN {for(i=0; i<=16; i++) printf 2**i" "}')
awk
is used to print out a list of powers of 2 which will then be used by parallel
.
Alternatively:
parallel "echo hello {}" ::: $(printf '%s\n' 2^{0..16} | bc | tr '\n' ' ')
This prints out the numbers 1 to 16 as part of the string x^2
, printf
ensures each number is on a separate line. bc
then computes the actual numbers, and tr
removes the newlines again.
Use {= =} (available in version 20140822 and later):
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}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.