Hi,

I think I have found a bug in sort field selection algorithm. The

following are the examples:

$ ls -1 sfa*

sfa1001ext

sfa1002ext

sfa100ext

sfa10ext

sfa1ext

sfa200ext

sfa20ext

sfa2ext

sfa300ext

sfa30ext

sfa3ext

The goal is sort on the number. Before we get into it, let's look at

some warm up exercises first:

$ ls sfa* | sort -k 1.4

sfa1001ext

sfa1002ext

sfa100ext

sfa10ext

sfa1ext

sfa200ext

sfa20ext

sfa2ext

sfa300ext

sfa30ext

sfa3ext

$ ls sfa* | sort -n -k 1.4

sfa1ext

sfa2ext

sfa3ext

sfa10ext

sfa20ext

sfa30ext

sfa100ext

sfa200ext

sfa300ext

sfa1001ext

sfa1002ext

-- so far so good

$ ls sfa* | sort -n -k 1.4,1.4

sfa1001ext

sfa1002ext

sfa100ext

sfa10ext

sfa1ext

sfa200ext

sfa20ext

sfa2ext

sfa300ext

sfa30ext

sfa3ext

-- There is the bug! The output should be the same as previous one.

My sort comes along with RH8:

$ sort --v

sort (textutils) 2.0.21

Written by Mike Haertel and Paul Eggert.

The impat of this bug will make it impossible to sort in certain

circumstances. For example:

$ ls -1 sfb*

sfb10-B

sfb10000-A

sfb10001-A

sfb10002-A

sfb11-B

sfb12-B

sfb8-B

sfb9-B

sfb9998-A

sfb9999-A

We need to sort the list first by the characters then by the

numbers. There is no way to do it with the current sort program:

$ ls -1 sfb* | sort -t- -k2,2 -n -k1.4,1.4

sfb10-B

sfb10000-A

sfb10001-A

sfb10002-A

sfb11-B

sfb12-B

sfb8-B

sfb9-B

sfb9998-A

sfb9999-A

-- this should be the right way, but the result is wrong.

$ ls -1 sfb* | sort -t- -k2 -n -k1.4,1.5

sfb8-B

sfb9-B

sfb10-B

sfb10000-A

sfb10001-A

sfb10002-A

sfb11-B

sfb12-B

sfb9998-A

sfb9999-A

$ ls -1 sfb* | sort -t- -k2 -n -k1.4,1.6

sfb8-B

sfb9-B

sfb10-B

sfb11-B

sfb12-B

sfb10000-A

sfb10001-A

sfb10002-A

sfb9998-A

sfb9999-A

What do you think? Thanks

--

Tong (remove underscore(s) to reply)

*niX Power Tools Project: http://xpt.sourceforge.net/

- All free contribution & collection