How to sort a file by pure ASCII order?

How to sort a file by pure ASCII order?

Omer Zak w1 at zak.co.il
Sun Sep 14 16:59:32 IDT 2014


I encountered a counterintuitive behavior of 'sort' in modern Linux
releases.

I checked the sorting behavior of sort, as installed in Debian Jessie
and Ubuntu 14.04 LTS.
Turns out that the default behavior of sort (with locale=en_US.UTF-8) is
not to sort by ASCII order, but as if letters and digits are more
important to sort order than punctuation marks.

Attached please find a sort-test.txt file and the output of
sort < sort-test.txt (as the file actual.txt).

To show how would the output look like using pure ASCII sort, I sorted
sort-test.txt using python-sort.py (attached).
and got the result reproduced in correct.txt (attached).

The problem is then what options would get GNU sort to sort like
python-sort.py?

Can anyone shed a light on the matter?

--- Omer


-- 
No actual electrons, animals or children were harmed by writing this
E-mail message.
My own blog is at http://www.zak.co.il/tddpirate/

My opinions, as expressed in this E-mail message, are mine alone.
They do not represent the official policy of any organization with which
I may be affiliated in any way.
WARNING TO SPAMMERS:  at http://www.zak.co.il/spamwarning.html
-------------- next part --------------
a
b
c
d
C
B
z-a
z-c
z-B
z/d
z/f
z/E
zy-a
zy/A
zy/b
zy-B
-------------- next part --------------
a
b
B
c
C
d
z-a
z-B
z-c
z/d
z/E
z/f
zy-a
zy/A
zy/b
zy-B
-------------- next part --------------
A non-text attachment was scrubbed...
Name: python-sort.py
Type: text/x-python
Size: 102 bytes
Desc: not available
URL: <http://mailman.cs.huji.ac.il/pipermail/linux-il/attachments/20140914/6faa2efb/python-sort.py>
-------------- next part --------------
B
C
a
b
c
d
z-B
z-a
z-c
z/E
z/d
z/f
zy-B
zy-a
zy/A
zy/b


More information about the Linux-il mailing list