Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

change scientific notation to number in Linux

I have a file .txt like belowe

AXN1 6.9e+07 69000000
AXN2 7.2e+07 72000000
AXN2 81000000 81000000
AXN3 1.18e+08 118000000
AXN4 7.7e+07 77000000
AXN9 8e+07 80000000
AXN11 800000 800000
AXN11 2.9e+07 29000000
AXN12 48000001 48000001
AXN18 4.8e+07 48000000

I want get that

AXN1 69000000 69000000
AXN2 72000000 72000000
AXN2 81000000 81000000
AXN3 118000000 118000000
AXN4 77000000 77000000
AXN9 80000000 80000000
AXN11 800000 800000
AXN11 29000000 29000000
AXN12 48000001 48000001
AXN18 48000000 48000000

How can I do it at Linux? Thank you.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

That can be achieved using awk and its sprintf function:

$ awk '{$2=sprintf( "%d", $2)}1' alegria.txt 
AXN1 69000000 69000000
AXN2 72000000 72000000
AXN2 81000000 81000000
AXN3 118000000 118000000
AXN4 77000000 77000000
AXN9 80000000 80000000
AXN11 800000 800000
AXN11 29000000 29000000
AXN12 48000001 48000001
AXN18 48000000 48000000

To save it to file redirect the output to a tmp-file and then move it:

$ awk '{$2=sprintf( "%d", $2)}1' alegria.txt > alegria.tmp && mv alegria.tmp alegria.txt && cat alegria.txt
AXN1 69000000 69000000
AXN2 72000000 72000000
AXN2 81000000 81000000
AXN3 118000000 118000000
AXN4 77000000 77000000
AXN9 80000000 80000000
AXN11 800000 800000
AXN11 29000000 29000000
AXN12 48000001 48000001
AXN18 48000000 48000000
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading