How to sort two columns with exponents in bash
I need to sort some data from the "test" file (sample data):
1.03073 0.000193333 2.02417 2.15578
1.03073 0.0002 2.12005 2.14534
1.03073 1.33333e-05 100 0
1.03073 2e-05 100 0
so that it sorts first by the first column and then a second later. I tried with
sort -n -k1 -k2 -u test >test1
but it's a mess because he doesn't see the "e-5" part. Any ideas?
+3
source to share
1 answer
You can use -g
:
sort -k1,2 -g file
From man sort
:
-g, --general-numeric-sort
compare according to the total numerical value
Test
$ cat a
1.03073 0.000193333 2.02417 2.15578
1.03073 0.0002 2.12005 2.14534
1.03073 1.33333e-05 100 0
1.03073 2e-05 100 0
1.03073 2e-04 100 0
1.03073 2e-06 100 0
$ sort -k1,2 -g a
1.03073 0.000193333 2.02417 2.15578
1.03073 0.0002 2.12005 2.14534
1.03073 1.33333e-05 100 0
1.03073 2e-04 100 0
1.03073 2e-05 100 0
1.03073 2e-06 100 0
+6
source to share