Script for retrieving page numbers for index

I have a book of listings that looks like this…

12345 Some header here Some header here
Some header hereSome header hereSome header here
Some header hereSome header hereSome header here…

and the index of the book looks like this…

12345 Some header here - pg1

Is there a script that will take the 5 digit number of the listing and find the page number
that listing is on?

The book is in Quark, but I can use textedit if needed.

Any help would be appreciated.

http://lists.apple.com/archives/applescript-users/2006/Aug/msg00202.html

might help.