SORT command > sorting decimal numbers in columns on a file not working !

SORT command > sorting decimal numbers in columns on a file not working !

Post by Albert » Wed, 07 Jun 2006 04:10:30



Hi. I try to sort a column on a file containing decimal numbers. I use
Sse Linux 9.1. Then I try to do this:


doasidpoas   opipo     7.8
kjkljkljklji   kjklj   35.7
kljkljkl       kljkl   2.3
dopasidp       poipo   0.2
kjkljlkl       kjkl    0.0
kljkljkjl      ljlk    0.8
jklhkljkl      kjkl    0.0
kljkljkljl     kjkl    0.1

dopasidp       poipo   0.2
jklhkljkl      kjkl    0.0
kjkljlkl       kjkl    0.0
kljkljkjl      ljlk    0.8
kljkljkljl     kjkl    0.1
kljkljkl       kljkl   2.3
doasidpoas   opipo     7.8
kjkljkljklji   kjklj   35.7

kjkljkljklji   kjklj   35.7
doasidpoas   opipo     7.8
kljkljkl       kljkl   2.3
kljkljkljl     kjkl    0.1
kljkljkjl      ljlk    0.8
kjkljlkl       kjkl    0.0
jklhkljkl      kjkl    0.0
dopasidp       poipo   0.2

As you can see the sorting order is not correct. What am I doing wrong ?
I also tried to use '-g' option instead of '-n' but doesnt work.

Any idea ?

Thanks
Alberto

 
 
 

SORT command > sorting decimal numbers in columns on a file not working !

Post by Stephane CHAZELA » Wed, 07 Jun 2006 04:27:21


2006-06-05, 19:10(+00), Alberto:
> Hi. I try to sort a column on a file containing decimal numbers. I use
> Sse Linux 9.1. Then I try to do this:


> doasidpoas   opipo     7.8
> kjkljkljklji   kjklj   35.7
> kljkljkl       kljkl   2.3

[...]

-n is for integer decimal sorting.

GNU sort, that you seem to have has an extension for "generic
numerical values".

sort -k3,3g

--
Stphane

 
 
 

SORT command > sorting decimal numbers in columns on a file not working !

Post by Albert » Wed, 07 Jun 2006 06:41:04


I tried Stephane CHAZELAS escribi:
> 2006-06-05, 19:10(+00), Alberto:
>> Hi. I try to sort a column on a file containing decimal numbers. I use
>> Sse Linux 9.1. Then I try to do this:


>> doasidpoas   opipo     7.8
>> kjkljkljklji   kjklj   35.7
>> kljkljkl       kljkl   2.3
> [...]

> -n is for integer decimal sorting.

> GNU sort, that you seem to have has an extension for "generic
> numerical values".

> sort -k3,3g

I tried sort -k3,3g but it doesnt sort correctly. Perhaps I have
incorrect sort installed. How could I solve it ?
 
 
 

SORT command > sorting decimal numbers in columns on a file not working !

Post by Stephane CHAZELA » Wed, 07 Jun 2006 07:16:05


2006-06-05, 21:41(+00), Alberto:
[...]

Quote:>>> Hi. I try to sort a column on a file containing decimal numbers. I use
>>> Sse Linux 9.1. Then I try to do this:
[...]
>>> kjkljkljklji   kjklj   35.7
>>> kljkljkl       kljkl   2.3
[...]
>> sort -k3,3g

> I tried sort -k3,3g but it doesnt sort correctly. Perhaps I have
> incorrect sort installed. How could I solve it ?

What output are you expecting and what output are you getting?

sort --version

will tell you if you have a GNU sort.

Try:

LC_ALL=C sort -k3,3g < input-file

in case your sort expects the decimal point to be something else
than ".".

--
Stphane

 
 
 

SORT command > sorting decimal numbers in columns on a file not working !

Post by Albert » Thu, 08 Jun 2006 01:28:48


Stephane CHAZELAS escribi:
Quote:> 2006-06-05, 21:41(+00), Alberto:
> [...]
>>>> Hi. I try to sort a column on a file containing decimal numbers. I use
>>>> Sse Linux 9.1. Then I try to do this:
> [...]
>>>> kjkljkljklji   kjklj   35.7
>>>> kljkljkl       kljkl   2.3
> [...]
>>> sort -k3,3g

>> I tried sort -k3,3g but it doesnt sort correctly. Perhaps I have
>> incorrect sort installed. How could I solve it ?

> What output are you expecting and what output are you getting?

> sort --version

> will tell you if you have a GNU sort.

> Try:

> LC_ALL=C sort -k3,3g < input-file

> in case your sort expects the decimal point to be something else
> than ".".

I solved with
export LC_ALL=POSIX

thanks !