Misunderstanding of sort behavior

Hi everyone,

I use the sort from the 5.3.0 coreutils package. I have a file consisting in 5 fields
separated by a single space, with no leading or trailing blanks.
I want to sort it first according to the 4th field, which contains integers
(some of them negative), and secondly on the second field, which is a string
(i.e. if two lines have the same value for the 4th field I want them sorted according
to the second field).

After reading the man page and the info page I came up with
sort sort -k 4,4n -k 2,2 correspondance_tmp
(where correspondance_tmp is my file), but this seems not to work because
when I ask it to check if the result is sorted according to the 4th field it says
no. So I think I must not know how to specify the fields properly.

Here is a short extract from my working session:
$ sort -k 4,4n -k 2,2 correspondance_tmp > correspondance
$ sort -c -k4,4n correspondance
sort: correspondance:37: disorder: . 0-00.com 1 -1 43
$ cat correspondance | awk '{print $4}' | sort -cn
$

This last check of sortedness exists without error, which means the
corresponding file is correctly sorted.
The line about which sorts complains in file correspondance is in
a large group of lines all having -1 for 4th field, so it seems to be
correctly placed.
All my locales are set to "C".

If anyone has any advice I'd greatly appreciate.

Looks like a bug.
You could try the latest version:
ftp://alpha.gnu.org/gnu/coreutils/coreutils-5.90.tar.bz2
A compresssed version of your problematic input file would be useful

OK, problem solved.

It's not a bug, I just misunderstood the behaviour of the -c option of sort:
it does not just check that the file is sorted according to the field specified
by the -k option, it checks that the file is identical to what sort would produce
on the file when sorting it according to this field.
The behavior of sort when two lines have the same value for the specified
field is to compare the whole of these two lines to sort them with respect
to one another. Providing the --stable option causes it instead to leave
them in the order they were in in the original file.
Therefore running sort -c --stable correctly identifies that the file is sorted
according to the desired field in my case.

Here's a short example of this behaviour:
$ cat test_sort
bbb aaa 2
aaa bbb 2
aaa aaa 1
$ sort -k 3,3n -k 2,2 test_sort
aaa aaa 1
bbb aaa 2
aaa bbb 2
$ sort -k 3,3n -k 2,2 test_sort | sort -c -k 3,3n
sort: -:3: disorder: aaa bbb 2
$ sort -k 3,3n -k 2,2 test_sort | sort -c --stable -k 3,3n

This last check is successful.
Thanks for your help, it's the designing of this small example that helped me
understand what the problem was!