Artificial intelligent assistant

Does comma come before numbers when sorting? I have a file `foo` whose contents are 140,22 236,224 2,86 If I sort it with `sort foo` I get the same result. This tells me that `,` comes after numbers, or at the very least that `,` comes after `3`. Paradoxically, the following happens: $echo -e "2\n,\n3" | sort , 2 3 Which tells me that `,` comes before `2`. I don't get it. Can someone please explain?

Sort order depends on your locale, so there's probably some odd interpretation going on there. I get the same results as you on my system. Here, a comma is _ignored_ by the locale. Hence, if we add `276` and `296` to your list:


$ sort /tmp/tosort
140,22
236,224
276
2,86
296


This also explains the results from your second command. The comma isn't being sorted _first_ , but being ignored. Hence, it's essentially sorting a empty string. If you add a literal empty string to your test, you'll also see it at the beginning.


$ echo -e "2\
,\
3\
" | sort

,
2
3


(It's unclear to me why the empty string precedes the comma. I suspect that the comma is used when there is a tie.)

You will get more predictable results using a "standard" POSIX locale.


$ export LC_ALL=C
$ sort foo
140,22
2,86
236,224

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 3a27ed9874a54207392765fa01360e96