0

Considering the sort key: a, a01 and a02, if there's no trailing fields, the sort result looks like:

$ cat test1
a01
a
a02
$ sort test1
a
a01
a02
$

But if there are tailing fields, something goes strange:

$ cat test2
a01 7
a 12
a02 42
$ sort test2
a01 7
a02 42
a 12
$

Why does the key "a" fall from the top to the bottom of the sort result?

My sort version is "sort (GNU coreutils) 5.97".

1 Answer 1

1

The man page for my version of sort says:

***  WARNING  *** The locale specified by the environment affects sort order.  
Set LC_ALL=C to get the traditional sort order that uses native byte values.

And indeed, if I set LC_ALL=C and run sort on your second example, I get:

$ LC_ALL=C sort < tosort 
a 12
a01 7
a02 42

Your default locate is probably something other than C.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.