Possible Duplicate:
How to sort numeric and literal columns in Vim
I have to sort the below lines based on thread id.
Internal thread 0 bound to OS proc set {1} Internal thread 1 bound to OS proc set {5} Internal thread 2 bound to OS proc set {9} Internal thread 10 bound to OS proc set {41} Internal thread 9 bound to OS proc set {37}
When I issue :!sort -n
they get sorted like this:
Internal thread 0 bound to OS proc set {1} Internal thread 1 bound to OS proc set {5} Internal thread 10 bound to OS proc set {41} Internal thread 2 bound to OS proc set {9} Internal thread 9 bound to OS proc set {37}
But I need them to be sorted like this:
Internal thread 0 bound to OS proc set {1} Internal thread 1 bound to OS proc set {5} Internal thread 2 bound to OS proc set {9} Internal thread 9 bound to OS proc set {37} Internal thread 10 bound to OS proc set {41}
column happens to be the first column with a decimal number, note that you could use simply :sort n , as the help says: "With [n] ... sorting is done on the first decimal number in the line..." This doesn't apply to your case, but might to somebody elses.
Just use Vim's own sort function. Visually highlight the text (or use a range) and type:
:sort n
Documentation is available here: http://vim.wikia.com/wiki/Sort_lines
Or in Vim itself: :help sort
(Edited to reflect an important point of clarification from dash-tom-bang and the reference to Vim's own help file.)
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