How do I sort lines semi-lexiographically in emacs -- i.e., lexiographically, except that 3 gets sorted above 11? For example, I have a large collection of data, each entry of which looks like
[ 5, 3, 21, 1600000 ],
[ 3, 11, 21, 6400000 ],
[ 3, 3, 102, 1600000 ],
etc...
M-x sort-lines sorts this as
[ 3, 11, 21, 6400000 ],
[ 3, 3, 102, 1600000 ],
[ 5, 3, 21, 1600000 ],
but I would really like this sorted as
[ 3, 3, 102, 1600000 ],
[ 3, 11, 21, 6400000 ],
[ 5, 3, 21, 1600000 ],
Thanks!
sehe gives a good solution. Here it is in Emacs:
C-u M-| sort -k2n -k3n
Run that with your region selected and it will be replaced with the sort
ouput!
I don't use emacs, but in vim I'd do:
%!sort -k2n -k3n
(possibly using the other key columns as well, I can't tell form the sample)
I'm not starting the editor war here... I'm just pretty sure that emacs allows you to filter through a shell command as well, so this will help!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With