Command Line Examples

PowerGREP supports a long list of command line parameters. The examples below show some of the more common usages. Replace the file names in the examples with full paths to your actual files.

The examples use more double quotes than strictly necessary. You only need them around parameters that contain spaces and to specify empty values. The examples use them around all values that have a good chance of containing spaces when you replace the example values with your actual values.

Open PowerGREP from Another Application

These examples show how you could use PowerGREP’s command line parameters to launch PowerGREP from another application, such as a file manager or a code editor, ready to perform an action on the file(s) you’re working with in the other application. If the other application has its own search feature then you could pass the search term you were using in the other application to PowerGREP too. You could add the /reuse parameter to any of these command lines if you want PowerGREP to reuse an idle instance if you left one open.

Launch PowerGREP ready to perform an action on a single file:

PowerGREP5.exe /file "searchme.txt"

Launch PowerGREP with several files marked in the File Selector:

PowerGREP5.exe /file "searchme.txt;metoo.txt;methree.txt"

Launch PowerGREP with a single folder marked in the File Selector:

PowerGREP5.exe /folder "C:\My Documents"

Launch PowerGREP with several folders marked in the File Selector:

PowerGREP5.exe /folder "C:\My Documents;C:\Your Documents"

Launch PowerGREP with a folder and its subfolders marked in the File Selector:

PowerGREP5.exe /folderrecurse "C:\My Documents"

Launch PowerGREP with a folder and its subfolders and the contents of any .zip archives marked in the File Selector:

PowerGREP5.exe /folderrecurse "C:\My Documents" /configarchives "ZIP archives only"

Launch PowerGREP with a single archive marked in the File Selector. Note that we mark the archive as if it were a folder. When PowerGREP searches inside archives, it treats them as if they were folders.

PowerGREP5.exe /configarchives "All archives" /folderrecurse "archive.zip"

Launch PowerGREP with a folder and its subfolders marked in the File Selector restricted to certain types of files (C source and header files):

PowerGREP5.exe /folderrecurse "C:\My Code in C" /masks "*.c;*.h" "" "" "" 0

Launch PowerGREP to search through all .7z archives in a particular folder. Note again that *.7z is passed as a file mask for folders rather than files:

PowerGREP5.exe /folderrecurse "C:\My Documents" /configarchives "All archives" /masks "" "" "*.7z" "" 0

Launch PowerGREP to search through C source and header files in all .7z archives in a particular folder:

PowerGREP5.exe /folderrecurse "C:\My Code Archives" /configarchives "All archives" /masks "*.c;*.h" "" "*.7z" "" 0

Launch PowerGREP with a search term pre-filled on the Action panel:

PowerGREP5.exe /simple /literal /searchtext "find me"

Launch PowerGREP with a search term and replacement text pre-filled on the Action panel:

PowerGREP5.exe /replace /literal /searchtext "before" /replacetext "after"

Launch PowerGREP with a regular expression pre-filled on the Action panel:

PowerGREP5.exe /simple /regex /searchtext "regexp?"

You can combine any of the above examples specifying files or folders with any of the examples specifying a search term. This marks a single file and specifies a regex:

PowerGREP5.exe /file "searchme.txt" /simple /regex /searchtext "regexp?"

Execute PowerGREP from The Command Line

These examples show how you can accomplish basic tasks directly from the command line. You can easily add these to a batch file or script to automate simple tasks.

Run a search and show the results on the Results panel in PowerGREP:

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 /simple /literal /searchtext "find me" /execute

Run a search and save the results into a PowerGREP Results File that you can open on the Results panel to inspect the results in the future. You don’t need to use the /resultsoptions parameter as you can change the settings on the Results panel after opening the .pgr file.

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 /simple /literal /searchtext "find me" /save "results.pgr" /execute /quit

Do the same without showing PowerGREP:

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 /simple /literal /searchtext "find me" /save "results.pgr" /execute /silent

Run a search and save the results into an HTML file that can be opened in a web browser to see detailed search results. This time you need the /resultsoptions parameter to format the results in the HTML file as you want:

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 /simple /literal /searchtext "find me" /resultsoptions "match context number" "file void" "before after" "alnum inc" "none" "inline" /save "results.html" /execute /quit

Use /silent instead of /quit to do the above without showing PowerGREP.

Run a search and write the search matches to a target file. Note we’re now using /search instead of /simple:

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 /search /literal /searchtext "find me" /target single "single folder" "results.txt" /backup history /quick /quit

Do the same without showing PowerGREP:

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 /search /literal /searchtext "find me" /target single "single folder" "results.txt" /backup history /silent

Run a search and replace, modifying the files that were searched through:

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 /replace /literal /searchtext "before" /replacetext "after" /target same /backup history /quick /quit

Do the same without showing PowerGREP:

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 /replace /literal /searchtext "before" /replacetext "after" /target same /backup history /silent

Execute Previously Saved Actions

Executing previously saved actions makes it easy to consistently repeat actions in the future. It also lets you specify settings that are available on the File Selector or Action panels that do not have direct command line parameters. PowerGREP uses an XML-based file format. You can make a script generate temporary file selection or action files to configure anything that can be configured on the File Selector and Action panels.

Repeat a search of which the results were previously saved with the Results|Save menu item or the /save parameter and a .pgr file extension:

PowerGREP5.exe "results.pgr" /execute

Repeat the search and write the new results to the same .pgr file:

PowerGREP5.exe "results.pgr" /save "results.pgr" /execute /quit

Do the same without showing PowerGREP:

PowerGREP5.exe "results.pgr" /save "results.pgr" /execute /silent

Execute an action that was saved with the Action|Save on the files that were marked on the File Selector panel when the action was saved:

PowerGREP5.exe "action.pga" /execute

Execute a previously saved action, ignoring any settings made on the File Selector panel when the action was saved:

PowerGREP5.exe /folder "C:\My Documents" /masks "*.txt" "" "" "" 0 "action.pga" /execute

Execute a previously saved action using the settings on the File Selector panel when the action was saved, but overriding the folder that is searched through:

PowerGREP5.exe "action.pga" /folder "C:\My Documents" /execute

Execute a previously saved action, overriding the search term and the folder that is searched through:

PowerGREP5.exe "action.pga" /folder "C:\My Documents" /searchtext "find me" /execute

Execute an action that was saved with the Action|Save on a file selection saved with File Selector|Save:

PowerGREP5.exe "filesel.pgf" "action.pga" /execute