Reputation: 20774
I have a variable holding a list of exponents:
p=`seq -1 0.25 2`
I want to obtain from this a list of powers of 10, and assign it to another variable. In this case the expected result would be:
0.1, 0.177828, 0.316228, 0.562341, 1., 1.77828, 3.16228, 5.62341,
10., 17.7828, 31.6228, 56.2341, 100.
How can I do this?
Upvotes: 1
Views: 128
Reputation: 10199
Using gnu awk you can do this:
L=$( LC_ALL=C seq -1 0.25 2 | awk '{print 10**$1}' )
echo $L
> 0.1 0.177828 0.316228 0.562341 1 1.77828 3.16228 5.62341 10 17.7828 31.6228 56.2341 100
(I needed the LC_ALL=C
due to my regional settings.)
Upvotes: 3
Reputation: 10345
$ answers=`seq -1 0.25 2 | sed 's/^/e(/; s/$/ * l(10))/' | bc -l`
$ printf '%s\n' $answers
.10000000000000000000
.17782794100389228012
.31622776601683793320
.56234132519034908039
1.00000000000000000000
1.77827941003892280121
3.16227766016837933197
5.62341325190349080387
9.99999999999999999992
17.78279410038922801203
31.62277660168379331945
56.23413251903490803828
99.99999999999999999840
Upvotes: 3