sort ignoring less than and greater than characters

Viewed 128

sort command is ignoring character '<' and '>' characters for sorting.

$ cat 1
< word6
< word5
> word1
> word2
> word3
< word4
$ sort 1
> word1
> word2
> word3
< word4
< word5
< word6
$

I want to sort the content by first character ('<' has ascii code 60, '>' ascii code 62) also. I want the below output from sort:

< word4
< word5
< word6
> word1
> word2
> word3

Is it possible to get above output ?

1 Answers

Sort considers your locale (language and character encoding). Depending on the language the same character code might be sorted differently.
It seems like you want to sort by ASCII codes. In this case, set the locale to C:

LC_ALL=C sort yourFile

prints the expected output. The system locale is not altered. Only this one sort command is affected.

Related