Collect Page Numbers

PowerGREP deals with plain text files. Plain text files consist of unformatted text, so there's no real concept of a page. Still, plain text files can contain page breaks represented by ASCII character 12 decimal, also known as the form feed control character. Some text editors, such as EditPad Pro and PowerGREP's built-in editor, allow page breaks to be inserted by pressing Ctrl+Enter and show them as horizontal lines.

PowerGREP's built-in decoders that convert PDF files and XPS files into plain text (so PowerGREP can search through them) also insert page breaks that match the page transitions in the original PDF and XPS files. You can make PowerGREP search for these page breaks to determine the page numbers. In this example we'll do this to get search results that indicate on which page each search match was found. We'll use the "file sectioning" feature to split the file into one section per page. The main search then processes the PDF or XPS one page at a time, with the section number being the page number.

  1. Select the PDF files you want to search through in the File Selector.
  2. Select a file format configuration such as "proprietary formats" that converts PDF and XPS files to plain text.
  3. Start with a fresh action.
  4. Set the action type to "collect data".
  5. Set "file sectioning" to "split along delimiters".
  6. To use each page break as the delimiter to divide the file into sections (pages), we need to set the search term for the file sectioning to a page break. There are two ways to do this. Choose whichever way you find more comfortable.
  7. Specify your search term(s) in the main part of the action.
  8. In the collect box, use the match placeholder %SECTIONN% as a placeholder for the page number. E.g. %MATCH% on page %SECTIONN% collects found me on page 7 when the main part of the action finds "found me" in the 7th section (page).
  9. Click the Search button to run the search.

You can find this action in the PowerGREP5.pgl standard library as "Collect page numbers".