queueueueueue
queueueueueue

Reputation: 21

Why does sort -n sort like this>

I have a file with the following lines:

4/3
4/7
3/5
3/6
2/4

When sorting using sort without any arguments, it arranges the lines like you would expect. When using sort -n the output is as follows:

3/5
3/6
4/3
4/7
2/4

I don't understand why this happens.

Upvotes: 2

Views: 88

Answers (1)

Andreas Louv
Andreas Louv

Reputation: 47119

A way to reproduce it is by adding zero width spaces in front of each line except for 2/4:

U+200B ZERO WIDTH SPACE [Cf]

The following is a hex string containing said arrangement:

% echo "e2808b342f330ae2808b342f370ae2808b332f350ae2808b332f360a322f340a" \
  | xxd -r -p | sort -n
3/5
3/6
4/3
4/7
2/4

I doubt this is the case but maybe there is other non printable characters, you could try with a hex dump:

xxd -p < my_file

Upvotes: 2

Related Questions