Sort an Index by Page Number
What if you use the index feature but need the result in page number order instead of alphabetical order? The easiest way to make this kind of list is probably to use the Table of Contents feature instead of the index feature. (Inside the Table of Contents dialog box, there is a checkbox labeled Sort Entries in Alphabetical Order… but you only see it when you click the More Options button inside that dialog box.)
However, if you already have your index, and you need to put it in chronological order (by page number) instead of alphabetical, you could use this three step process. Here’s my starting point:
First, I’m going to use the Find/Change dialog box to search for
^(.+?)\t(\d+?)$ and replace it with
$2\t$1 which means “find all the text from the beginning of the paragraph up to a tab, and then followed by some numbers until the end of the paragraph, and then replace it with the second part (the numbers) then a tab, then the first part (the text up to the tab).”
All you need to do is select the text frame or text and then double-click that script in the panel. Poof! It’s in page number order.
Finally, step three is to reverse the order again, by again using a grep find/change. Here you can search for
^(\d+)\t(.+)$ and then replace it with
Note that in this case, I swapped the tab (\t) with a right-indent tab (~y) so that I don’t have to worry about a tab stop or where that page number is going to go (it’ll always go to the right margin). In the image above you’ll see that I have already performed the Change All.
Warning: There is one very important thing that you need to watch out for when doing these kinds of grep find/changes… if you have applied local formatting (font or color changes, for example) to the text, it will get all messed up! That’s because GREP appears to work on the underlying text separately from the formatting. Very frustrating. So: save your work before you do any kind of change all; and instead of applying local formatting, use Nested Styles and GREP Styles to format your text in these kinds of documents.