Sorting exponential notation

Hi,
I just want to sort my file with exponential notation. For example:

1;2;4;s
1;5e-01;4;s
1;1;4;s

I used sort -gk2, but it does not sort in the correct way. What's wrong?

Try:

sort -t\; -k2,2g

Thanks ..it works

---------- Post updated at 04:38 PM ---------- Previous update was at 04:24 PM ----------

the numbers stands for the columns right? 2g = second column wtih exp. notation

2,2 means the sort key starts at column 2 and ends at column2, so col 2 only.

ok thanks .. when I want another column, e.g. only 3 the -k,3,3g

that would be -k3,3g without the comma after the k.

right sorry ..many thanks for your help

---------- Post updated at 05:03 PM ---------- Previous update was at 04:50 PM ----------

Sorry for asking again: But I tried it on my data and it does not function;(.
So my real data looks like:
XX300890;4.27691979504843e-01;4;KL144469220
XY300890;4.27691979504843e-05;4;KL144469220
XY300890;4.27691979504843e-03;4;KL144469220

And I use your code..to sort the second column... but I do not get the expected result???

Strange, I get:

$ sort -t\; -k2,2g infile
300890;4.27691979504843e-05;4;144469220
300890;4.27691979504843e-03;4;144469220
300890;4.27691979504843e-01;4;144469220

Which looks alright to me. Did you use: -t\; ?

sorry I edit the text ..i think the reason is that i some columns are numbers and in others there are strings:

nils$ sort -t\; -k2,2g test.txt
 
XX10914755;0.0879836449881873-e10;1;33854866;CSMD2;T;C;I_2321282;POEA;8;43212072;43212115
XX12745618;0.00069063786440612;1;4019438;hCG_2036596;T;C;I_2321282;POEA;8;43212072;43212115
XX1547793;0.0000076396450281944;1;57739400;DAB1;T;C;I_2321282;POEA;8;43212072;43212115
XX3762296;0.00334938423169702;1;31003973;LAPTM5;A;G;I_2321282;POEA;8;43212072;43212115

Hi, I think there is an error in your input file, no? If I use:

XX10914755;0.0879836449881873e-10;1;33854866;CSMD2;T;C;I_2321282;POEA;8;43212072;43212115
XX12745618;0.00069063786440612;1;4019438;hCG_2036596;T;C;I_2321282;POEA;8;43212072;43212115
XX1547793;0.0000076396450281944;1;57739400;DAB1;T;C;I_2321282;POEA;8;43212072;43212115
XX3762296;0.00334938423169702;1;31003973;LAPTM5;A;G;I_2321282;POEA;8;43212072;43212115

I get:

$ sort -t\; -k2,2g infile346c
XX10914755;0.0879836449881873e-10;1;33854866;CSMD2;T;C;I_2321282;POEA;8;43212072;43212115
XX1547793;0.0000076396450281944;1;57739400;DAB1;T;C;I_2321282;POEA;8;43212072;43212115
XX12745618;0.00069063786440612;1;4019438;hCG_2036596;T;C;I_2321282;POEA;8;43212072;43212115
XX3762296;0.00334938423169702;1;31003973;LAPTM5;A;G;I_2321282;POEA;8;43212072;43212115

No there is no error .. I copied also yours ..i do not know whats wrong .. is there any other function, which I can use for sorting ..I am so confused know ;(

I meant the - and the e were switched around in your example number: 0.0879836449881873-e10 should be 0.0879836449881873e-10 . What result did you get?

---------- Post updated at 00:52 ---------- Previous update was at 00:47 ----------

Is there a difference when you convert everything to scientific first? e.g.:

awk 'BEGIN{FS=OFS=";"}{$2=sprintf("%e",$2)}1' infile | sort -t\; -k2.2g

yes..I have seen it ..but the problem still remains,

nils$ sort -t\; -k2,2g sort.txt 
XX10914755;0.0879836449881873e-10;1;33854866;CSMD2;T;C;I_2321282;POEA;8;43212072;43212115
XX12745618;0.00069063786440612;1;4019438;hCG_2036596;T;C;I_2321282;POEA;8;43212072;43212115
XX1547793;0.0000076396450281944;1;57739400;DAB1;T;C;I_2321282;POEA;8;43212072;43212115
XX3762296;0.00334938423169702;1;31003973;LAPTM5;A;G;I_2321282;POEA;8;43212072;43212115

I it sorts only for the first number before ".",e.g.

nils$ sort -t\; -k2,2g sort.txt 
XX1547793;1.0000076396450281944;1;57739400;DAB1;T;C;I_2321282;POEA;8;43212072;43212115
XX10914755;2.0879836449881873e-10;1;33854866;CSMD2;T;C;I_2321282;POEA;8;43212072;43212115
XX3762296;3.00334938423169702;1;31003973;LAPTM5;A;G;I_2321282;POEA;8;43212072;43212115
XX12745618;5.00069063786440612;1;4019438;hCG_2036596;T;C;I_2321282;POEA;8;43212072;43212115

I do not know ..whats wrong

FWIW, I am getting:

XX10914755;2.0879836449881873e-10;1;33854866;CSMD2;T;C;I_2321282;POEA;8;43212072;43212115
XX1547793;1.0000076396450281944;1;57739400;DAB1;T;C;I_2321282;POEA;8;43212072;43212115
XX3762296;3.00334938423169702;1;31003973;LAPTM5;A;G;I_2321282;POEA;8;43212072;43212115
XX12745618;5.00069063786440612;1;4019438;hCG_2036596;T;C;I_2321282;POEA;8;43212072;43212115

using sort (GNU coreutils) 7.4

where do get the info which one I use??

sort --version

otherwise:

man sort