How could I use the sort-regexp-fields to emulate the sort-numeric-fields. I tried like this:
123
345
90
80
1999
M-x sort-regexp-fields
Regexp specifying records to sort: \ ([0-9]+\)
Regexp specifying key within record: \, \#1
But it can’t work.
what I really want to sort is something like this:
foo index: 123
index: 345 boo
…
the question is: I want to sort the lines by the number after the word “index”, but the number is not in the same field, they just have a word “index” before it. what should I do to complete this? anybody can help me?
sort-regexp-fieldsdoesn’t do lexicographical compare, and there’s no trivial way to get it to do that. That said, we can use a trick of defining our own command, and using that command to signal to some advice to shoe-horn in a lexicographical compare.The following command does what you want, provided you mark the region around the lines you want to compare: