Journal Synonymous Dastard's Journal: Using sort
Damn sort, not working the way I thought.
I post this mainly as a self-reminder, but it might help others.
sort -n
is just not enough to numerically sort several columns.
For example:
$ (echo "12 12"; echo "2 12"; echo "2 2"; echo "12 2") | sort -n
2 12
2 2
12 12
12 2
The first column is correctly sorted, but not the second one.
One solution (I don't know if this is the best one) is adding -k1 -k2. It works but it means that you have to know how many columns there are.
$ (echo "12 12"; echo "2 12"; echo "2 2"; echo "12 2") | sort -n -k1 -k2
2 2
2 12
12 2
12 12
Using sort More Login
Using sort
Slashdot Top Deals