Gnu sort: stray characters in field specification Gnu sort: stray characters in field specification shell shell

Gnu sort: stray characters in field specification


The two fields in -k arg are the START AND END fields. You can specify -k ANY NUMBER OF TIMES, to sort on multiple keys. So, -k 1,1 -k 2,2 -k 3,3 will sort first on field 1, then field 2 then field 3.


Oops, I should have taken the man page more literally. The definition for KEYDEF says

F[.C][OPTS][,F[.C][OPTS]]

and not

F[.C][OPTS][,F[.C][OPTS]...]

which means that only 1 or 2 fields can be supplied, not an arbitrary number. This explains the error.

As a side note, I believe there is still an error in the man page. The KEYDEF definition says that the stop position defaults to the line's end. This can't be true, can it? IMO it should be the stop position defaults to the field's end.

UPDATE: My explanation is NOT correct. See the answer provided by @tedtoal for a correct explanation.