Collect Paragraphs (Split along Blank Lines)

This example illustrates how you can use file sectioning to process files paragraph by paragraph, where a paragraph is a block of lines delimited from other paragraphs by one or more blank lines.

You can find this action in the PowerGREP5.pgl library as "Collect paragraphs (split along blank lines)".

  1. Select the files you want to search through in the File Selector.
  2. Start with a fresh action.
  3. Select "split along delimiters" from the "file sectioning" list. Leave the section search type as "regular expression".
  4. In the Section Search box, enter the regular expression (?:\r\n){2,}+. This regular expression matches two or more consecutive line breaks, or one or more consecutive blank lines. If lines containing only whitespace should be considered blank, use the regular expression \r\n(?:[ \t]*+\r\n)++.
  5. Turn on the "collect whole sections" checkbox.
  6. Set the action type to "search". Since we turned on the "collect whole sections" checkbox, there's no need to enter a text to be collected, so we can use the "search" action type instead of "collect data".
  7. Enter the search term you want to find in the paragraphs.
  8. Click the Preview button to see the results.

If you want to treat lines that consist of nothing but spaces and tabs as blank lines, use the regular expression \r\n(?:[ \t]*+\r\n)++ to find your sections. This regex also matches two or more line breaks. The difference is that it allows whitespace between each pair of line breaks. This makes it match one or more consecutive lines that do not contain anything except whitespace. You can find this action as "Collect paragraphs (split along whitespace-only lines)" in the library.