Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting a file as a fortan format

Status
Not open for further replies.

hill007

Technical User
Mar 9, 2004
60
US
Hi,

I am trying to format a large file.

An example input file is below:


0 0 0 0 0.00120833 0.00331665 0.00335832 0.00339165 0.00342499 0.00295832
0 0 0 0 0 0 0.000816663 0.00241666 0.00224999 0.00227499
0.000841663 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0


The output file would be like:

0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 1.2000e-03 3.3000e-03 3.4000e-03 3.4000e-03 3.4000e-03 3.0000e-03
0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 8.0000e-04 2.4000e-03 2.2000e-03 2.3000e-03
8.0000e-04 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00
0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00 0.0000e+00

The output file has a fortran format as: 10e12.4


Could someone please help as how to make this format in awk. I am new with awk.

Thanks.
 
In the awk man page take a look at the printf function:
printf "%.4e",$1

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
It seems not to work
Any error message ? Unexpected behaviour ?
What result get you ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,

Here is the output from your script.

0.0000e+0000.0000e+0008.4166e-0040.0000e+000
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top