bashsortinggnu-sort

Linux: GNU sort does not sort seq


Title sums it up.

$ echo `seq 0 10` `seq 5 15` | sort -n
0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15

Why doesn't this work?

Even if I don't use seq:

echo '0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15' | sort -n
0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15

And even ditching echo directly:

$ echo '0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15' > numbers
$ sort -n numbers 
0 1 2 3 4 5 6 7 8 9 10 5 6 7 8 9 10 11 12 13 14 15

Solution

  • sort(1) sorts lines. You have to parse whitespace delimited data yourself:

    echo `seq 0 10` `seq 5 15` | tr " " "\n" | sort -n