LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva
User Name
Password
Mandriva This Forum is for the discussion of Mandriva (Mandrake) Linux.

Notices


Reply
  Search this Thread
Old 03-13-2008, 10:04 AM   #1
ratti74
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Rep: Reputation: 0
Unhappy sort doesn't work


Hi,

I need to sort a numeric file but my sort command seems doesn't work!

When I use the command:
>sort -n infile
or
>sort -g infile

I obtain the same result that
>sort infile

That means that I get an alphabetically ordered file even if the file is a list of numbers.
I can't figure out what's the problem....could someone halp me, please?

My sort varsion is:
sort (coreutils) 5.2.1
Written by Mike Haertel and Paul Eggert.

Thank you !
 
Old 03-13-2008, 02:22 PM   #2
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by ratti74 View Post
Hi,

I need to sort a numeric file but my sort command seems doesn't work!
hmm... maybe we need to see a snippet of the file. Are all the number on one line? Seems to work for me... here's the file I used:

Code:
45 23 2 5 4253
23
423 253
 4253
4253
2
55 5 43
12
423 foo
 5
5
  6 hello
3

453
45
7
4 gah
4
57
3
453
... and the output:
Code:
sort -n some_file

2
3
3
4
4 gah
5
 5
  6 hello
7
12
23
45
45 23 2 5 4253
55 5 43
57
423 253
423 foo
453
453
4253
 4253
are you getting something else?
 
Old 03-14-2008, 04:31 AM   #3
ratti74
LQ Newbie
 
Registered: Mar 2008
Posts: 2

Original Poster
Rep: Reputation: 0
This is an example of in_file

2.26102e-10
5.28728e-05
1.43164e-05
1.43164e-05
1.99507e-11
2.79948e-12
4.90768e-10
2.34509e-13
1.32265e-12
8.57706e-16
9.83975e-12
1.81137e-05
9.16633e-16
2.81432e-05
2.81432e-05
0.000318926
6.34414e-06
0.000487889
4.01249e-16
2.82483e-06
4.09477e-09
4.09477e-09
1.09976e-05
5.26564e-03
1.08076e-09
2.54978e-10
1.94235e-08
0.000315027
0.000315027
5.14266e-07
6.51105e-02
8.51396e-07
3.42159e-09
1.42678e-08

When I use the command:
>sort -g in_file
I get...
0.000315027
0.000315027
0.000318926
0.000487889
1.08076e-09
1.09976e-05
1.32265e-12
1.42678e-08
1.43164e-05
1.43164e-05
1.81137e-05
1.94235e-08
1.99507e-11
2.26102e-10
2.34509e-13
2.54978e-10
2.79948e-12
2.81432e-05
2.81432e-05
2.82483e-06
3.42159e-09
4.01249e-16
4.09477e-09
4.09477e-09
4.90768e-10
5.14266e-07
5.26564e-03
5.28728e-05
6.34414e-06
6.51105e-02
8.51396e-07
8.57706e-16
9.16633e-16
9.83975e-12

When I use the command:
>sort -n in_file
I get...the same

0.000315027
0.000315027
0.000318926
0.000487889
1.08076e-09
1.09976e-05
1.32265e-12
1.42678e-08
1.43164e-05
1.43164e-05
1.81137e-05
1.94235e-08
1.99507e-11
2.26102e-10
2.34509e-13
2.54978e-10
2.79948e-12
2.81432e-05
2.81432e-05
2.82483e-06
3.42159e-09
4.01249e-16
4.09477e-09
4.09477e-09
4.90768e-10
5.14266e-07
5.26564e-03
5.28728e-05
6.34414e-06
6.51105e-02
8.51396e-07
8.57706e-16
9.16633e-16
9.83975e-12

the same if I use : sort in_file

It seems to me that options -g or -n doesn't work...
 
Old 03-14-2008, 04:47 AM   #4
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
what's the problem? it seems to be sorted properly.
 
Old 03-14-2008, 01:31 PM   #5
BrianK
Senior Member
 
Registered: Mar 2002
Location: Los Angeles, CA
Distribution: Debian, Ubuntu
Posts: 1,334

Rep: Reputation: 51
Quote:
Originally Posted by ratti74 View Post
This is an example of in_file

When I use the command:
>sort -g in_file
I get...
0.000315027
0.000315027
0.000318926
0.000487889
1.08076e-09
1.09976e-05
1.32265e-12
1.42678e-08
1.43164e-05
1.43164e-05
1.81137e-05
1.94235e-08
1.99507e-11
2.26102e-10
2.34509e-13
2.54978e-10
2.79948e-12
2.81432e-05
2.81432e-05
2.82483e-06
3.42159e-09
4.01249e-16
4.09477e-09
4.09477e-09
4.90768e-10
5.14266e-07
5.26564e-03
5.28728e-05
6.34414e-06
6.51105e-02
8.51396e-07
8.57706e-16
9.16633e-16
9.83975e-12
that's very odd. -g is supposed to recognize scientific notation, and it does on my machine:

Code:
sort -g /tmp/some_file2
4.01249e-16
8.57706e-16
9.16633e-16
2.34509e-13
1.32265e-12
2.79948e-12
9.83975e-12
1.99507e-11
2.26102e-10
2.54978e-10
4.90768e-10
1.08076e-09
3.42159e-09
4.09477e-09
4.09477e-09
1.42678e-08
1.94235e-08
5.14266e-07
8.51396e-07
2.82483e-06
6.34414e-06
1.09976e-05
1.43164e-05
1.43164e-05
1.81137e-05
2.81432e-05
2.81432e-05
5.28728e-05
0.000315027
0.000315027
0.000318926
0.000487889
5.26564e-03
6.51105e-02
don't know why yours isn't working? I'm using sort (GNU coreutils) 5.97
on Debian 4.0 (etch)
 
Old 03-14-2008, 11:46 PM   #6
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
oic it's the scientific notation . my mistake. perhaps as also BrianK is asking about versions, your sort command has no support of scientific notations in that version. Or perhaps it was compiled with disabled support for scientific notations. Try to recompile looking for options that enable support for such or try using newer versions of coreutils.
 
Old 03-15-2008, 12:57 AM   #7
billymayday
LQ Guru
 
Registered: Mar 2006
Location: Sydney, Australia
Distribution: Fedora, CentOS, OpenSuse, Slack, Gentoo, Debian, Arch, PCBSD
Posts: 6,678

Rep: Reputation: 122Reputation: 122
CentOS is version 5.97 too btw

Edit - and it sorts scientific notation fine

Last edited by billymayday; 03-15-2008 at 01:08 AM.
 
Old 03-15-2008, 01:03 AM   #8
konsolebox
Senior Member
 
Registered: Oct 2005
Distribution: Gentoo, Slackware, LFS
Posts: 2,248
Blog Entries: 8

Rep: Reputation: 235Reputation: 235Reputation: 235
ok.. and mistakes in library support too? perhaps?
 
  


Reply

Tags
sort



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
iptables seem to only sort of work... MrSako Linux - Security 24 08-29-2006 07:41 PM
Is there a line limit with the sort utility? Trying to sort 130 million lines of text gruffy Linux - General 4 08-10-2006 08:40 PM
sort +r ?? ravi.ravix Linux - General 1 07-07-2006 09:52 AM
Can't get "sort' to work on a particular column smkamene Programming 11 06-30-2006 10:37 AM
What sort of work is involved in k3b? robhargreaves Programming 5 05-04-2004 02:08 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Mandriva

All times are GMT -5. The time now is 02:14 PM.

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