LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-26-2011, 03:18 PM   #16
josesec
LQ Newbie
 
Registered: Jul 2010
Posts: 10

Original Poster
Rep: Reputation: 0

Code:
0000000   4   1   .   0       1   0   .   0       7  \n   3   9   .   0
0000020   0       -   0   .   1   0       2   8   .   0   0  \n   4   0
0000040   .   0   0       -   1   9   .   2   0       2   .   2   5  \n
0000060   4   1   .   0       2   0   .   0       1   0  \n   3   9   .
0000100   0   0       -   0   .   4   0       2   5   .   5   8  \n   3
0000120   9   .   0   0       -   0   .   2   0       2   6   .   7   2
0000140  \n   3   9   .   0   0       0   .   2   0       3   0   .   1
0000160   8  \n   4   0   .   0   0       -   1   9   .   1   0       2
0000200   .   1   6  \n   4   1   .   0       1   5   .   0       1   2
0000220  \n   3   9   .   0   0       -   0   .   3   0       2   6   .
0000240   9   8  \n   3   9   .   0   0       0   .   3   0       3   3
0000260   .   3   1  \n   3   9   .   0   0       0   .   0   0       2
0000300   6   .   7   8  \n   4   0   .   0   0       -   2   0   .   0
0000320   0       1   .   3   9  \n   4   0   .   0   0       -   1   9
0000340   .   0   0       2   .   0   5  \n   4   1   .   0       5   .
0000360   0       8  \n   4   0   .   0   0       -   9   .   9   0    
0000400   2   9   .   6   4  \n   3   9   .   0   0       0   .   1   0
0000420       2   8   .   1   3  \n   4   0   .   0   0       9   .   9
0000440   0       2   8   .   2   5
0000447
 
Old 06-26-2011, 04:04 PM   #17
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by josesec View Post
I have used the same matrix that you haved used in the last message and the result is that one:


41.0 5.0 8
41.0 10.0 7
41.0 15.0 12
41.0 20.0 10
40.00 -20.00 1.39
40.00 -19.00 2.05
40.00 -19.10 2.16
40.00 -19.20 2.25
40.00 -9.90 29.64
40.00 9.90 28.25
39.00 0.00 26.78
39.00 -0.10 28.00
39.00 0.10 28.13
39.00 -0.20 26.72
39.00 0.20 30.18
39.00 -0.30 26.98
39.00 0.30 33.31
39.00 -0.40 25.58

I have used sort -k1rn -k2n infile but I find still the problem with decimals (not well organized at all), I feel this must be a silly problem but I don't manage to fix it.

Thank you
The problem is simply that the minus sign is ignored and the fields are sorted numerically in respect of their absolute value. The solution may reside in your current locale settings. Please check them using the command:
Code:
locale
and post the output here. To be sure the file is sorted as desired, force the LC_COLLATE variable to be C or POSIX:
Code:
env LC_COLLATE=C sort -k1rn -k2n file
 
Old 06-26-2011, 05:01 PM   #18
josesec
LQ Newbie
 
Registered: Jul 2010
Posts: 10

Original Poster
Rep: Reputation: 0
LANG=es_ES.utf8
LC_CTYPE="es_ES.utf8"
LC_NUMERIC="es_ES.utf8"
LC_TIME="es_ES.utf8"
LC_COLLATE="es_ES.utf8"
LC_MONETARY="es_ES.utf8"
LC_MESSAGES="es_ES.utf8"
LC_PAPER="es_ES.utf8"
LC_NAME="es_ES.utf8"
LC_ADDRESS="es_ES.utf8"
LC_TELEPHONE="es_ES.utf8"
LC_MEASUREMENT="es_ES.utf8"
LC_IDENTIFICATION="es_ES.utf8"
LC_ALL=

I have tried this: env LC_NUMERIC=C sort -k1rn -k2n infile

and that works perfectly, thank you very much!
 
Old 06-26-2011, 05:19 PM   #19
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Glad it works! And I tried LC_NUMERIC=es_ES.utf8 and it (doesn't) works as in your previous example. The same for it_IT.utf8. I don't know why, but negative numbers are treated in a different way by the latin locales.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
shell programming problem sang_froid Programming 3 06-25-2007 06:00 AM
shell programming problem ratul_11 Programming 2 12-15-2005 12:05 AM
shell programming problem ratul_11 *BSD 2 12-14-2005 12:47 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration