Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is 'sort' broken on HP-UX (or am I going mad)?

Status
Not open for further replies.
Jun 22, 2000
6,317
AU
I can't for the life of me figure out why this is happening under HP-UX (both 11.11 and 11.23/11i v2):

[tt]$ cat t4
XP12K0 XP12K 0F288 CONNECTED A/A
XP12K0 XP12K 0F288 CONNECTED A/A
XP1283 XP128 045151B0016F DISCONNECTED _
XP12K0 XP12K 0F288 CONNECTED A/A
XP12K0 XP12K 0F288 CONNECTED A/A
13F XP128 20199 CONNECTED A/A
XP12K0 XP12K 0F288 CONNECTED A/A
XP10K_12K0 XP10K_12K 0F288 CONNECTED A/A
FAKE_ARRAY0 FAKE_ARRAY FAKE_ENCLR_SNO DISCONNECTED _
XP12K0 XP12K 0F288 CONNECTED A/A
$ sort -k 3,3 t4
XP1283 XP128 045151B0016F DISCONNECTED _
XP12K0 XP12K 0F288 CONNECTED A/A
XP12K0 XP12K 0F288 CONNECTED A/A
XP12K0 XP12K 0F288 CONNECTED A/A
XP12K0 XP12K 0F288 CONNECTED A/A
XP12K0 XP12K 0F288 CONNECTED A/A
XP12K0 XP12K 0F288 CONNECTED A/A
13F XP128 20199 CONNECTED A/A
XP10K_12K0 XP10K_12K 0F288 CONNECTED A/A
FAKE_ARRAY0 FAKE_ARRAY FAKE_ENCLR_SNO DISCONNECTED _
$[/tt]

Notice how the line in red has not been sorted correctly, i.e. it is not with the rest of the lines containing 0F288 in that field position. Why is this happening?

Sorting the same data on Linux yields the expected results.

There are no funny characters (that I can find) in the data. There are no tabs, all spaces.

If I pull out that field alone and sort it, the order is as expected. Also if I compress the white space into single spaces it works as well, so I think its related to white space somehow. Any clues, 'cause I'm baffled??

Annihilannic.
 
My wife kindly identified the problem.

This example illustrates it:

[tt]$ cat t5
7 d
3 c
4 b
2 e
8 a
$ sort -k 2,2 t5
8 a
7 d
4 b
3 c
2 e
$ sort -b -k 2,2 t5
8 a
4 b
3 c
7 d
2 e
$[/tt]

For some reason the operating systems I'm used to (Solaris, Linux, etc.) automatically ignore leading white space when you refer to fields using -k n,n, which to me is logical... if any number of spaces can separate fields, then surely they should not be significant in the sort! Anyway, as you can see, using the -b option fixes it.

In any case, I probably am going mad.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top