[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

`sort' - is this a (minor) bug, or just an unexpected behavior ?!?

From: me . myself
Subject: `sort' - is this a (minor) bug, or just an unexpected behavior ?!?
Date: Fri, 5 Apr 2002 13:32:37 +0200

sort --version

sort (textutils) 2.0.14
Written by Mike Haertel and Paul Eggert.
[April 2001]

and, FWIW

uname -a

Linux 2.4.7-10 #1 Thu Sep 6 17:27:27 EDT 2001 i686 unknown

I read man and info pages, but didn't find an explanation for the facts
below :
[anyway, please, bear in mind that english is not my mother tongue]

Consider a four-line text file, referred here as `file_name', which is made
of the following lines :

5               6c
3               7c
1               9c
4               8c

sort -k 2,2 file_name

returns correctly

5               6c
3               7c
4               8c
1               9c


sort -k 2.1,2.1 file_name

(say I want to ignore char[s] past the numerical values, I know that's trivial,
but assume
I have a very long file to sort and using a one char only key, speeds it
up significately)


1               9c
3               7c
4               8c
5               6c

that is, it sorts as if no key were given, using the entire line as the


the problem seems to be in the end delimiter of the key, as doing

sort -k 2.1,2 file_name

works as expected, returning

5               6c
3               7c
4               8c
1               9c


sort -k 2,2.1 file_name

returns the unexpected one

1               9c
3               7c
4               8c
5               6c

Hope this helps.


By the way, let me ask two related questions, whose answers I couldn't find
documented anywhere :

1) Sometimes I need to sort file using as key absolute char position, as
opposed to char
position relative to fields.

Say I want to sort a file using as unique key chars in columns 11 through
(Assume each line of the file has 25 or more chars)

I issue the following command

sort -k 1.11,1.16 other_file_name

and everything works, even if the first field has less than 11 chars, say
just 5 or 6)

[The same happens if I were to use two keys in place of one, say

sort -k 1.11,1.16 -k 1.21,1.23 other_file_name


Is that an undocumented feature, or just something which could stop working
with some next
release of `sort' (textutils) ?

2) What really happens when defining a key you express it in reverse order


sort -k 8,3 file_name_another

that is reversing fields (I assume my file has at least 8 fields)


sort -k 2.6,2.3 file_name_another

that is reversing char position in a field (I assume second filed is at
least 6 chars long)

It seems that the sort is performed as if no key were given,
using the entire line as the key; but I'm not sure.

David Fabiani


Abbonati a Tiscali!
Con Tiscali By Phone puoi anche ascoltare ed inviare email al telefono.
Chiama Tiscali By Phone all' 892 800        http://byphone.tiscali.it

reply via email to

[Prev in Thread] Current Thread [Next in Thread]