1

I am running Ubuntu 12 and a while back I wrote a small script file to manipulate a text file which I use for a workshop index.

The most important function is to sort the file into alphabetical order that I did with the command
sort -df
This worked well when first written as the directory sort paid attention to leading spaces and tabs placing lines of text with leading spaces at the head of the file.

It now will not do that and the same script file just does a straight alphabetical sort and ignores spaces. This is not what I need. Reading the manual (man) and other documentation seems to agree with me.

What can I do to return to what I need? Thanks for any help you can supply. Regards Charlie

1
  • 2
    How about some brief example lines that get sorted incorrectly, and how they "should" be?
    – Xen2050
    Jan 22, 2015 at 11:31

1 Answer 1

0

You need to set the LC_COLLATE=C before sorting.

Without using LC_COLLATE=C :

$ cat test.txt | sort -df abc abc abc baa baa baa

After using LC_COLLATE=C :

$ cat test.txt | env LC_COLLATE=C sort -df abc baa abc baa abc baa $

Refer to this link for more details :

https://stackoverflow.com/questions/7168596/why-does-the-unix-sort-utility-ignore-leading-spaces-without-the-option-b

The following link holds information regarding what the LC_* does https://unix.stackexchange.com/questions/87745/what-does-lc-all-c-do

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .