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.
CodePudding user response:
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