I guess everyone who uses at least from time to time the command line, knows about
sort(1). Very useful to quickly, well, sort a file. I had to do that a couple of minutes ago, to get data points in the right order for plotting with
gnuplot: I have a bunch of halo masses and from those I want to get the mass function
a. No problem methought
b:
cat data | sort -n -r > data_sorted9.94361e+14
9.94361e+13
9.94361e+13
9.94361e+13
9.94361e+13
9.88624e+14
9.86872e+14
9.86712e+14
...
Ah, bugger. That doesn't work. The masses are not integers but floating-point values. No worries,
sort is smart and can handle that, I just have to tell it:
cat data | sort -g -r > data_sorted
9.94361e+14
9.94361e+13
9.94361e+13
9.94361e+13
9.94361e+13
9.9176e+16
9.88624e+14
9.86872e+14
...
Ghee! Still not working! But it should? At least
-g is doing something different than
-n; though that doesn't help at all. Now, I had that same problem a couple of weeks ago and got it working. Writing down such things might be of help
c. But okay, lets ask Google.
No good. At least not without some really good query. But a thought hit me. Isn't sorting locale depending? And I am using
de_DE@euro. So, lets see:
cat data | LANG=C sort -g -r > data_sorted
3.19946e+18
1.18662e+18
9.31701e+17
7.51848e+17
7.27704e+17
7.13003e+17
5.41289e+17
5.29525e+17
...
Hooray! The C locale did the trick. That's what I wanted. Note: Always do numerical (especially general numeric, read floating point) sorting in the C locale.
a: That is just the mass on the x-axis and the number of halos having a higher mass than this on the y-axis.
b: The
-r to have the result being order descending, so that the line number automatically gives the number of halos with this or higher mass.
c: Exactly why I am writing this now. Next time I know where to look.