-2

I have a file as follows:

1   13.00000    12.9999999183917    8.160832898340686E-008  21148294
2   16.00000    15.9999995223584    -4.760327190211910E-007 21148294
3   9.000000    8.99999979262170    2.073783047507050E-007  21148295

I want an output like:

1   13.00000    12.9999999183917    0.0000000816083289340686    21148294
2   16.00000    15.9999995223584    -0.00000004760327190211910  21148294
3   9.000000    8.99999979262170    0.00000002073783047507050   21148295

Can anyone help me ? Thanks a lot!!

user3383949
  • 3
  • 1
  • 2
  • We don't want to do all the job for you! Here is a useful link: http://stackoverflow.com/questions/2474424/how-can-i-convert-between-scientific-and-decimal-notation-in-perl – user4035 Jul 25 '14 at 11:40
  • 1
    stackoverflow is not a place to ask people to write code for you. you are expected to have an idea of your problem and some code which you have tried to solve your problem. then you can ask questions about your code and it not working as expected. – Chris Doyle Jul 25 '14 at 11:42

1 Answers1

2

the key to this problem is to use printf to control the precision.

You should give an expected precision, e.g. the numbers in your 1st row and 2nd row have different precision. which one do you expect? or even a higher one? here is the example with awk. do some test on your own and pick the right one. It should at least show you the way, to get you start:

kent$  cat f
1   13.00000    12.9999999183917    8.160832898340686E-008  21148294
2   16.00000    15.9999995223584    -4.760327190211910E-007 21148294
3   9.000000    8.99999979262170    2.073783047507050E-007  21148295

kent$  awk '{$4=sprintf("%.23f",$4)}7' f
1 13.00000 12.9999999183917 0.00000008160832898340686 21148294
2 16.00000 15.9999995223584 -0.00000047603271902119099 21148294
3 9.000000 8.99999979262170 0.00000020737830475070501 21148295

kent$  awk '{$4=sprintf("%.24f",$4)}7' f 
1 13.00000 12.9999999183917 0.000000081608328983406864 21148294
2 16.00000 15.9999995223584 -0.000000476032719021190989 21148294
3 9.000000 8.99999979262170 0.000000207378304750705009 21148295

you can change the %.xxf pattern

Kent
  • 189,393
  • 32
  • 233
  • 301
  • could you please explain a little bit more clear of spritf() and the meaning of %.24f and the number 7 in your code? Thanks – user3383949 Jul 26 '14 at 17:30
  • sprintf does same as printf, difference is, it doesn't print but return as string. `%.24f` float number with precision 24 after decimal. `7` is same as `print`, in awk non-zero value means default action:print. @user3383949 – Kent Jul 26 '14 at 22:13