[This is the rewrite of a similar question I asked backwards... Sorry for the confusion!]
I'm confused about leading s and the standard sort
utility. Consider the contents of myfile
:
a
b
a
Executing sort -t : myfile
yields an unexpected result, at least to me:
a
a
b
Does that make sense? <space>
should come either before a-z
(as is the case in ASCII), or after. In the first case I would expect
a
b
a
while in the second case
a
b
a
Why, then, does sort
seem to apply the -b
option (ignore leading s) if when it wasn't included? In fact, to be safe I added the -t
option in order to have exactly one field in each line. (According to the POSIX standard, "A field comprises a maximal sequence of non-separating characters and, in the absence of option -t, any preceding field separator." sort myfile
yields the same output, which is also unexpected.)
Thanks in advance!
It depends on the locale. With
LC_COLLATE=en_US.utf8 sort myfile
I get your unexpected result, and with
LC_COLLATE=C sort myfile
I get your expected result. Also see bash sort unusual order. Problem with spaces?
(I don't know why sort handles -b and -t like this.)
$ sort -t : foo
a
a
b
$ env LC_ALL=C sort -t: foo
a
b
a
From the man page : * 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With