I'd like some advice on changing the formatting of some data in a file.
I have a large amount of data in a file. This is a output from a large Fortran program, it is formatted for a latex table. I wish to change the formatting but can not rerun the Fortran program with alternative formatting for the output. I've been playing with sed but not got very far.
A single line from a table is currently in the format
0.1 & 0.166685D+01 & 0.162768D+01 & 0.139468D+01 & 0.126904D+01 & 0.133247D+01 \\
I wish to change it to
0.1 & $0.16668510^{01}$ & $0.16276810^{01}$ & $0.13946810^{01}$ & $0.12690410^{01}$ & $0.133247 10^{01}$ \\
I currently have
#!/bin/bash
sed -i 's/D\+./ 10^{/g' $1
which gets me as far as
0.1 & 0.166685 10^{01 & 0.162768 10^{01 & 0.139468 10^{01 & 0.126904 10^{01 & 0.133247 10^{01 \\
but I still need to add the closing brace and wrap each number in a pair of `$' symbols.
In an ideal word I would also change the data to 3 d.p as well but this is less important.
Any sed / regex masters able to help, or maybe a suggestion of another tool which may be better suited to this problem.
Thanks
Tommy
I've just realised in the example all of the powers are +01 in this line, this is chance, they can be anything and vary though the file, positive and negative. Another example line with some NaNs thrown in.
0.3 & 0.634620D-02 & NaN & NaN & -0.312678D-02 & 0.192654D-03 \\