Define a Search Action
1. Start with selecting the kind of action you want to execute in the “action type” drop-down list in the upper left corner of the Action panel. As soon as you do so, the Action panel will rearrange itself slightly. Not all options are available for all action types.
- simple search: Display all search matches in each file, so you can inspect each search match and its context.
- search: Display all search matches, with additional options for file sectioning and target files.
- collect data: Collect a piece of text based on the search match using replacement text syntax. Create a new file with all the collected text, or create separate files for each source file.
- count matches: Count matches per search term. Different matches of the same regex are all counted towards that regex. Search terms without matches are also indicated in the results.
- list files: Display a list of files matching, or not matching, the search criteria. The fastest search method. Allows you to copy, move, delete, zip, and unzip the listed files via the target file creation setting.
- file or folder name search: Search through the names of files and/or folders, rather than through the contents of files. Allows you to copy, move, delete, zip, and unzip the listed files via the target file creation setting.
- file or folder name collect: Collect a piece of text based on a search match found in the file or folder’s name using replacement text syntax and path placeholders. Create a new file with all the collected file name parts.
- rename files or folders: Rename files or move files into different folders by searching and replacing through the file’s name or path.
- search and replace: Replace all search matches in each file, modifying either the original file or a copy of it.
- search and delete: Delete all search matches in each file, modifying either the original file or a copy of it.
- merge files: Collect the text of all files in which a search match is found into one or more new files.
- split files: Collect search matches into new files, using replacement text syntax to specify the target file for each search match.
2. Select the kind of search term you want to use from the “search type” list. Again, the Action panel will rearrange itself so you can enter that kind of search term. PowerGREP supports four kinds of search terms, which you can enter in three ways:
- Literal text: Any piece of text; words, phrases, whatever.
- Regular expression: A pattern describing the form of the text you want to match. This is the most powerful way to search. Read the regular expression tutorial to learn everything about regular expressions.
- Free-spacing regular expression: A regular expression that ignores spaces and comments in the pattern, allowing you to format it freely.
- Binary data: Arbitrary data that you can enter in hexadecimal mode. Useful for searching through binary files.
- Single item: Enter one piece of text, one regular expression, or one chunk of binary data.
- List of items: Separately enter as many search items as you want. Choose this method to key in multiple items in PowerGREP.
- Delimited items: Enter multiple search items all together, delimited by whichever characters you want. Choose this method if you want to copy and paste an already delimited list of items into PowerGREP.
3. Toggle search options:
- Non-overlapping search: When searching for a list of items, turn on non-overlapping search to process each file only once, searching for all items at the same time. See the reference section in this help file learn the implications of overlapping search.
- Case sensitive search: Turn on if the difference between uppercase and lowercase letters is significant.
- Adapt case of replacement text: Make the replacement text automatically all lowercase, all uppercase or all title case depending on the search match. Only available for search-and-replace and “collect data” actions.
- Dot matches newlines: When searching for a regular expression, make the dot match all characters, including line breaks.
- Whole words only: Only return search matches that consist of one or more complete words.
- List only files matching all terms: Display only files matching all search terms. Only available when the action type is “list files” or “search”, and the search type is a list.
4. When the action type is “search” or “collect data”, specify how matches should be collected.
- Group results for all files: Save only one output file with all the collected matches, rather than creating one file for each file searched through.
- Group identical matches: Collect identical matches only once in each output file (i.e. once for the whole action when grouping results for all files, otherwise once for each file searched through). If you turn off the grouping options, all matches are collected in the order they are found.
- Sort collected matches: When grouping matches, select to save them into the output file in alphabetic order, or sorted by the number of times each match was found.
- Minimum number of occurrences: When grouping matches, do not save matches that occur fewer times than you specify.
5. If you want to exclude some files from the action based on their contents, use the “filter files” option. An additional set of controls for entering search terms will appear.
6. Select a file sectioning option if you don’t want to search through entire files. An additional set of controls for entering search terms will appear. Select the “split along delimiters” sectioning type to make the main action (steps 1 through 4 above) process only those parts of each file between the matches of the sectioning search terms. Select “search for sections” to make the main action process the matches of the sectioning search terms. To really make use of “search for sections”, the sectioning search term should be a regular expression.
7. When sectioning a file, additional options affecting the main action (steps 1 through 4 above) are available.
- Match whole sections only: Only return search matches of the main part of the action that match whole sections.
- Collect/replace whole sections: When making replacements or collecting data, replace or collect the whole section, even if the main action search terms match the section only partially.
- Invert search results: Make the main action match sections in which the main search terms cannot be found. Only available in combination with “collect/replace whole sections”. If the action type is “list files”, this option has a different meaning, since the main action does not involve individual search matches. In “list files” mode, inverting search results makes PowerGREP lists those files in which the main action’s search terms cannot be found.
- List only sections matching all items: Retain only matches from sections in which all the search terms of the main action can be found. Search matches found in sections that contain only some of the search terms are discarded.
8. Turn on “extra processing” if you want to apply an extra search-and-replace to the replacement text in a search-and-replace action, or the text to be collected in a “collect data” action. When you do so, an extra set of controls for entering search terms will appear. This second search-and-replace will be executed on the replacement text or on the text to be collected, each time the main search finds a match.
9. If you plan to study the search results on the Results panel in PowerGREP, you can make things easier by collecting extra context before and/or after the match. Context is only used for display purposes on the Results panel.
10. Specify target file options. If the action type is “list files”, “file or folder name search”, or “file or folder name collect”, PowerGREP can save the file names of the files that are found into a target file. If the action type is “search and replace” or “search and delete”, the target settings determine if the replacements are made in the files being searched through, or in copies of those files. When the action type is “collect data”, PowerGREP saves search matches or collected text to into either a single target file for the whole action, or into one file for each file searched through.
11. When creating target files, set the backup file options to make sure backup copies are made when files are overwritten. Backup copies are required to be able to undo action in the Undo History.
12. To test the action, click the Preview button in the Action toolbar. PowerGREP will execute the search without creating or overwriting any files, or doing anything else you might regret. Click the Execute button to execute the action for real. Click the Quick Execute button to save time when you don’t need full details of the search results.
When PowerGREP finishes running the search, a full report appears on the Results panel. Unless you used the Quick Execute button, the results are highly detailed.
If you want to add the action to a library or save it into an action file, enter a description of the action in the Comments field to help you remember the purpose of the action.