I want to take the following input
Average Box 1: 0.520522 Std. Dev. Box 1: 0.00297154
...print the first number (the average) rounded to a certain digit, where that digit is defined by the first significant digit of the ROUNDED std. dev.
e.g.
--> Rounded Std 0.003 <-- (so third digit)
--> 0.521 (in this case)
To give a border case:
Average Box 1: 0.52156 Std. Dev. Box 1: 0.0099675
--> Rounded Std 0.01 <-- (so second digit)
--> 0.52 (in this case)
Can I do this all via some manner of Awk magic? If so, how? If not, what COULD I use to do it (my last resort is a C program, but shell programs seem more efficient)?
(This is for data extraction on a research project, aka /nothomework.)