? SORT Command Is Buggy

Hi,

I have reason to believe that Windows' built-in SORT command is buggy. I'm experiencing it with XP SP1 with all current updates (Aug.20.06).

Here's one way to reproduce it:

create a text file containing this:

a
A
B
b
r
R
S
s
X
x
Y
y
z
Z

As you can see it only has a mix of a few upper and lower case letters. It is very simple to make it easier to see the bug. Save it (eg: foo.txt) and open a command prompt. Type "type foo.txt" then type "sort foo.txt". The sorted one SHOULD display this:

A
a
B
b
R
r
S
s
X
x
Y
y
Z
z

But it displays this instead:

A
a
B
b
R
r
s
S
X
x
y
Y
Z
z

The S and Y are not sorted correctly.

I've got an even worse example. I created three files, each with every ASCII character from the space to the tilde (32-126) by itself on a separate line, but not in the same order. I then sorted each file, expecting the three to now be identical, but they were not!!! The above problem manifested in the files. Some of the letters were out of order, but only in some of the files, in some they were correct.

What the heck is going on? Can anyone reproduce it to confirm it's buggy?

:confused:

Thanks.
[1428 byte] By [Synetech] at [2007-11-20 0:40:24]
# 1 Re: ? SORT Command Is Buggy
I did it a couple of times. I wonder what the algorithm is because I get the following letter upper-case first...
BDGHKMSTUVWXY
...and the others give the lower-case first.
acefijlnopqr
PeejAvery at 2007-11-10 3:40:10 >
# 2 Re: ? SORT Command Is Buggy
So you're saying that they letters are sorted by letter, but the case is inconsistent?

Try creating a few files and putting the same content in each but in different orders. Sort them. They should now be identical but they are not.

I haven't checked yet, but I'm sure SORT.exe from DOS works fine (not the one by DataLight for DOS 7 though, that's buggy too.)

I needed a sorting app yesterday and since sort.exe was so defective, I had to get a port of the UNIX sort command.
Synetech at 2007-11-10 3:41:10 >
# 3 Re: ? SORT Command Is Buggy
So you're saying that they letters are sorted by letter, but the case is inconsistent?Sort.exe is case insensitive. So, it doesn't case about the caseing of the letters.

- petter
wildfrog at 2007-11-10 3:42:11 >
# 4 Re: ? SORT Command Is Buggy
Sort.exe is case insensitive. So, it doesn't case about the caseing of the letters.
If it is case insensitive, then why does it order some one way, and some the other?
PeejAvery at 2007-11-10 3:43:17 >
# 5 Re: ? SORT Command Is Buggy
If it is case insensitive, then why does it order some one way, and some the other?It's probably using an unstable sorting algorithm.

Wikipedia on sorting algorithms (http://en.wikipedia.org/wiki/Sorting_algorithms):Stability: stable sorting algorithms maintain the relative order of records with equal keys (i.e. values). That is, a sorting algorithm is stable if whenever there are two records R and S with the same key and with R appearing before S in the original list, R will appear before S in the sorted list.- petter
wildfrog at 2007-11-10 3:44:17 >
# 6 Re: ? SORT Command Is Buggy
Sort.exe is case insensitive. So, it doesn't case about the caseing of the letters.

- petter

I thought of that (why there isn't at least a switch to make it case sensitive is beyond me) but it doens't hold up because of the multiple file-scenario I described; sometimes the upper comes first, sometimes the lower, and it's different for different files.
Synetech at 2007-11-10 3:45:16 >