Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UNIX sort ignores whitespaces

Tags:

Given a file txt:

ab a c a a 

When calling sort txt, I obtain:

a a ab a c 

In other words, it is not proper sorting, it kind of deletes/ignores the whitespaces! I expected this to be the behavior of sort -i but it happens with or without the -i flag.

I would like to obtain "correct" sorting:

a a a c ab 

How should I do that?

like image 688
dagnelies Avatar asked Aug 03 '11 08:08

dagnelies


1 Answers

Solved by:

export LC_ALL=C 

From the sort() documentation:

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.

(works for ASCII at least, no idea for UTF8)

like image 115
dagnelies Avatar answered Sep 23 '22 00:09

dagnelies