Originally Posted by bakunin
There are some "sort" intrinsics to be considered and i think you haven't covered them all yet. This might not have any impact on your test file, but may well change the sorting order in another sample.
The default behavior of "sort" is to sort from the field/position given in te argument to the "-k" option to the end of line. That means:
sort -k 2 /some/file
will sort on field 2 first, in case f2 is equal on field 3, if this is equal too on field 4, etc. to the end of line. As you want to search on a last name - first name basis you have to state that:
sort -k 2,2 -k 1,1
You are lucky that you use only full fields, because it is possible to base sorting order on a sub-field starting at the n-th character of a certain field. Alas, character-numbering is sometimes 1-based and sometimes zero-based, depending on "-t" or "-b" being used - as i learned myself recently the hard way.
I hope this helps.
Very close... According to the standards (and the sort utilities I've used tend to follow the standards pretty closely), what you said about sort -k 2
is exactly correct. But, sort -k 2,2
sorts on the 2nd field and if two or more lines compare equal on that field, the entire line is used as the secondary sort key. So sort -k 2,2
performs exactly the same sort as sort -k 2,2 -k 1,1