Apply an Extra Search-And-Replace to Target Files

This example shows how you can use the Sequence panel in PowerGREP to run an extra search-and-replace on each target file produced by a PowerGREP action. This is different from the "extra processing" part of a PowerGREP action. This is different from the "extra processing" feature on the Action panel, which performs an extra search-and-replace on each replacement text or each text to be collected, handling each bit of text separately. The Sequence panel allows you to run a whole new action on the target files, reprocessing each file as a whole.

Suppose you want to condense consecutive spaces into single spaces in your target files when running a "collect data" action. If you used the "extra processing" feature to search for {2,} and replace with a single space, you'd condense consecutive spaces within each search match that is collected into the file. But if one search match ends with a single space and the next match starts with a single space, the target file will still end up with two consecutive spaces. The reason is that the "extra processing" processes each search match separately. It sees a single space at the end of the first match, and a single space at the start of the second match, neither of which are replaced because the regex doesn't match them. To condense all consecutive spaces, even those that were part of different matches, we need to search for {2,} through the target file as a whole.

  1. Prepare the "collect data" action on the File Selector and Action panels. Don't worry about consecutive spaces just yet.
  2. Start with a fresh sequence.
  3. Click the New Step button on the Sequence panel to add the contents of the Action panel as the first step in the sequence.
  4. Start with a fresh action.
  5. Set the action type to "search and replace".
  6. In the Search box, enter the regular expression {2,}. This regular expression matches two or more consecutive line spaces.
  7. In the Replacement box, enter a single space.
  8. Click the New Step button on the Sequence panel to add the contents of the Action panels as the second step in the sequence.
  9. With the second step still selected on the Sequence panel, select "target files from other step" in the "file selection" drop down list.
  10. Select step 1 in the "step" drop-down list. The second step is now configured to process the target files created by the first step.
  11. Click the Quick button on the Sequence panel to execute both steps. The first step collects the search matches. When that's done, the second step condenses consecutive spaces.