In my trade (Astrophysics), I often find myself having to do something on a daily basis that no-one else appears to need. Two examples: scatter plots and sorting files with multiple columns of pure numbers.
My life would change if Excel made scatter plots by default and if the Linux sort command sorted multiple columns of numbers by default (or at least with the simple addition of the -n flag). Neither is true.
At least let me address how to get the sort command to work correctly on files that contain columns of numbers.
Say you have a file called foo that looks like this:
22500. 1000. 200. 100.
22500. 450. 200. 100.
22500. 400. 220. 50.
22000. 1000. 220. 100.
22000. 1000. 200. 20.
22000. 1000. 220. 20.
22500. 1000. 200. 20.
22000. 450. 200. 100.
22000. 400. 220. 50.
You want to have it sorted numerically, by first column, then second, then third, then fourth.
We expect:
22000. 400. 220. 50.
22000. 450. 200. 100.
22000. 1000. 200. 20.
22000. 1000. 220. 20.
22000. 1000. 220. 100.
22500. 400. 220. 50.
22500. 450. 200. 100.
22500. 1000. 200. 20.
22500. 1000. 200. 100.
No biggie you say, use the -n flag (for numeric sort).
sort -n foo
This is what you get, for some inexplicable reason:
22000. 1000. 200. 20.
22000. 1000. 220. 100.
22000. 1000. 220. 20.
22000. 400. 220. 50.
22000. 450. 200. 100.
22500. 1000. 200. 100.
22500. 1000. 200. 20.
22500. 400. 220. 50.
22500. 450. 200. 100.
Here is what we get if we specifically sort the second column, using numerical sort
sort -k2,2n foo
22000. 400. 220. 50.
22500. 400. 220. 50.
22000. 450. 200. 100.
22500. 450. 200. 100.
22000. 1000. 200. 20.
22000. 1000. 220. 100.
22000. 1000. 220. 20.
22500. 1000. 200. 100.
22500. 1000. 200. 20.
When used on a single column, numerical sort works (numbers are recognized as numbers). Used on multiple columns, numerical sort fails (numbers are treated as text).
And so to get multiple columns of numbers to sort numerically for real with numerical sort, one has to use the n flag column by column. To get the desired result, use:
sort -k1,1n -k2,2n -k3,3n -k4,4n foo
Yep, a joy when the said file contains 15 columns of numbers... And why that is not the default behavior escapes me.