Sort lexicographically in bash

bashsorting

I want data to be sorted in the way Python sorts it, comparing ASCII values. But sort command seems too clever for that. Take a look. Since '.' < '9':

$ sort
.
9
^D
.
9

and :

$ sort
1.
19
^D
1.
19

These two are fine. But for some reason, if I just add characters to the ends:

$ sort
1.c
19z
^D
19z
1.c

Probably it tries to read that as a number or something. I don't want that, I want it to sort stuff comparing ASCII values of each character. Couldn't find such an option in man, any ideas?

Best Answer

The described behaviour is probably an effect of locale. Turn off locale settings for sort:

$ echo '1.c
19z ' | LC_ALL=C sort
1.c
19z
Related Question