Computing.Net > Forums > Unix > numeric sort

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

numeric sort

Reply to Message Icon

Name: mgonzalo
Date: June 5, 2007 at 00:30:39 Pacific
OS: B.11.11
CPU/Ram: HP-UX
Comment:

hello, I have a file that has 3 columns and I want to make a numeric sort with third
column in ascending order.
the file of serious departure (file1).
1 TATE DANCER -12
2 STANISLESS 0
3 UN CAPO 7
4 BABIA -3
5 ZAGATO -2
6 ELDAMAR -10
7 ALABARDERO -7
8 DUDU -8.5
9 OCHO REALES 3
10 CARMENTA -2.5
11 ALBARREAL -6
12 ARNOIA -7
13 RIVALLERO -4
14 VAILLANT PRINCE 4
15 TORCAL -4.5
16 CASTROGONZALO -6
17 BEST SUPER -17
18 THE BREAKERS -13
19 KIZAS -2
20 DANS LES ETOILES-22.5


if I make the sort with these parameters it leaves me

sort -r -k 1.29,1.32 file1

3 UN CAPO 7
14 VAILLANT PRINCE 4
9 OCHO REALES 3
2 STANISLESS 0
8 DUDU -8.5
7 ALABARDERO -7
12 ARNOIA -7
16 CASTROGONZALO -6
11 ALBARREAL -6
15 TORCAL -4.5
13 RIVALLERO -4
4 BABIA -3
20 DANS LES ETOILES-22.5
10 CARMENTA -2.5
5 ZAGATO -2
19 KIZAS -2
17 BEST SUPER -17
18 THE BREAKERS -13
1 TATE DANCER -12
6 ELDAMAR -10

but I would want that this came out.
3 UN CAPO 7
14 VAILLANT PRINCE 4
9 OCHO REALES 3
2 STANISLESS 0
5 ZAGATO -2
19 KIZAS -2
10 CARMENTA -2.5
4 BABIA -3
13 RIVALLERO -4
15 TORCAL -4.5
16 CASTROGONZALO -6
11 ALBARREAL -6
7 ALABARDERO -7
12 ARNOIA -7
8 DUDU -8.5
6 ELDAMAR -10
1 TATE DANCER -12
18 THE BREAKERS -13
17 BEST SUPER -17
20 DANS LES ETOIL -22.5

that options should use in the sort?

"La experiencia es algo maravilloso. Nos permite reconocer un error cada vez que lo volvemos a cometer.", Franklin P. Jones



Sponsored Link
Ads by Google

Response Number 1
Name: nails
Date: June 5, 2007 at 07:00:56 Pacific
Reply:

First, if the field seperator is white space, your data file is NOT necessarily 3 columns. If the second column has a space like:

THE BREAKERS

this is actually two columns. I took your data file and placed an "X" in the offending places:

TATEXDANCER -12
2 STANISLESS 0
3 UNXCAPO 7
4 BABIA -3
5 ZAGATO -2
6 ELDAMAR -10
7 ALABARDERO -7
8 DUDU -8.5
9 OCHOXREALES 3
10 CARMENTA -2.5
11 ALBARREAL -6
12 ARNOIA -7
13 RIVALLERO -4
14 VAILLANTXPRINCE 4
15 TORCAL -4.5
16 CASTROGONZALO -6
17 BESTXSUPER -17
18 THEXBREAKERS -13
19 KIZAS -2
20 DANSXLESXETOILES -22.5

Now, this command does the proper sort:

sort -n -r -k 3,3 datafile

This doesn't necessarily solve your problem given your data file.


0

Response Number 2
Name: 321bug123
Date: August 21, 2007 at 10:53:20 Pacific
Reply:

A similar example:

# sort -k 2.7bn sort | sort -k 2.6bn | sort -k 2.5bn | sort -k 2.4bn

cluster_var dsk9g
cluster_home dsk10c
archive dsk13c
oracle9 dsk19c
oracle920 dsk20c
orascr dsk24h
root2_domain dsk50a
root1_domain dsk51a
sde9 dsk54c
oracle10g dsk55c
oracle8_RV0 dsk991c
sde9_RV0 dsk999c
archive_RV0 dsk1000c
oralogs_RV0 dsk1001c


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


merge 2 files using perl Script to find & dele...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Unix Forum Home


Sponsored links

Ads by Google


Results for: numeric sort

Numerical sort with sort www.computing.net/answers/unix/numerical-sort-with-sort/7380.html

sort data www.computing.net/answers/unix/sort-data/7134.html

sorting problem sorting fields? www.computing.net/answers/unix/sorting-problem-sorting-fields/7772.html