43
242
44. Command Line Parameters
PowerGREP can be fully controlled from the command line. This allows you to use PowerGREP from batch
files or scripts and add PowerGREP as an external tool to other applications.
All parameters are optional. You can use as many or as few of them as you want. The order of the parameters
on the command line is irrelevant, except that when you specify both files and options, the files should be
specified before options. This to ensure that PowerGREP loads the file first, and then applies the options you
specified. If you specify the options first, they’ll be replaced by whatever was saved in the file.
If a parameter requires a value as a second parameter, the second parameter must follow right after the first
one. Values must always be specified as a separate parameter (i.e. be separated from the parameter by a
space). Values are indicated between sharp brackets in the list below. Remember that if a value contains
spaces, you must put double quotes around it (eg:
"search text"
) to make sure the value is interpreted as a
single parameter. For some parameters, the number of values is variable. Make sure to specify the correct
number of values. If you want to leave a required value blank, specify two double quotes. E.g.
/replacetext ""
blanks the replacement text.
Opening Files via The Command Line
You can specify any number of files of the command line, but only one file of each kind. You can specify one
file selection file, one action file, one results file, one library file and one undo history file. The file will be
loaded into the corresponding panel. In addition, you can specify one file of any other file. That file will be
opened in the built-in file editor.
File selections are saved in file selection files, action files and results files. If you specify two or all three of
these files on the command line, PowerGREP will use the file selection from the file selection file, or from
the action file if you didn’t specify a file selection file. Only when you don’t specify either a file selection file
or an action file, will PowerGREP read the file selection from the results file.
In similar vein, action definitions are saved in both action files and results files. If you specify both an action
file and results file on the command line, PowerGREP will read the action definition from the action file.
If you specify options that affect the file selection or action, PowerGREP will load the file, and then use the
options to modify the settings. In this situation, PowerGREP’s caption bar will not indicate the name of the
file selection file or action file.
File Selection, Action and Results Options
Use the command line parameters below to change basic settings in the file selection and action definition.
Not all settings you can make in PowerGREP’s user interface can be made via the command line. To control
the additional settings, first save a file selection file and/or action file in the user interface. Then pass that file
on the command line, before any of the options listed below.
1.
/simple
sets the action type to ´simple searchµ.
2.
/search
sets the action type to ´searchµ.
87
243
3.
/collect
sets the action type to ´collect dataµ.
4.
/find
sets the action type to ´list filesµ. This action type was known as ´find filesµ in PowerGREP 3,
hence the name of the command line parameter.
5.
/findname
sets the action type to ´search file namesµ.
6.
/rename
sets the action type to ´rename filesµ.
7.
/replace
sets the action type to ´search-and-replaceµ.
8.
/delete
sets the action type to ´search-and-deleteµ.
9.
/merge
sets the action type to ´merge filesµ.
10.
/split
sets the action type to ´split filesµ.
11.
/searchtext <text>
sets the search term(s) of the main part of the action to ´textµ. If you have more
than one search term, use one
/searchtext
parameter in combination with
/delimitsearch
.
12.
/replacetext <text>
sets the replacement text or text to be collected to ´textµ.
13.
/searchbytes <bytes>
sets the search term of the main part of the action. The <bytes> value must be
a string of hexadecimal bytes. Changes the search type to binary data.
14.
/replacebytes <bytes>
sets the replacement bytes or bytes to be collected. The <bytes> value must
be a string of hexadecimal bytes. Changes the search type to binary data.
15.
/searchtextfile <file path>
<charset>loads the search term(s) for the main part of the action
from a file. If the file contains more than one search term, use
/delimitsearch
to specify the delimiter. If
the file also contains the replacement text, use
/delimitreplace
to specify the delimiter.
You can specify an additional value after the file name to indicate the character set or text encoding used by
the file you’re reading the search terms from. You can use the same identifiers used by XML files and HTML
files to specify character sets, such as
utf-8
,
utf-16le
, or
windows-1252
. You can omit this parameter if
the file starts with a Unicode signature (BOM). The default is your computer’s default Windows code page.
16.
/searchbytesfile <file path>
loads the search term(s) for the main part of the action from a file.
The file should contain the actual bytes you want to search for (unlike the
/searchbytes
parameter which
expects the hexadecimal representation of the bytes). Changes the search type to binary data. If the file
contains more than one search term, use
/delimitsearch
to specify the delimiter. If the file also contains
the replacement bytes, use
/delimitreplace
to specify the delimiter.
17.
/regex
sets the search type to a regular expression.
18.
/literal
sets the search type to literal text.
19.
/delimitprefix <delimiter>
sets the search prefix label delimiter to ´delimiterµ. Also sets the search
type to a delimited list.
72
244
20.
/delimitsearch <delimiter>
sets the search item delimiter to ´delimiterµ. Also sets the search type
to a delimited list.
21.
/delimitreplace <delimiter>
sets the search pair delimiter to ´delimiterµ. Also sets the search type
to a delimited list.
22.
/optnonoverlap <0|1>
Sets the option ´non-overlapping searchµ. Only has an effect when the search
type is a delimited list.
23.
/optdotall <0|1>
Sets the option ´dot matches newlinesµ. Only has an effect when the search type is a
regular expression.
24.
/optwords <0|1>
Sets the option ´whole words onlyµ. Does not have any effect when the search type is
a regular expression.
25.
/optcase <0|1>
Sets the option ´case sensitiveµ.
26.
/optadaptive <0|1>
Sets the option ´adaptive caseµ.
27.
/optinvert <0|1>
Sets the option ´invert resultsµ. Only has an effect when the action type is ´list
filesµ, or when you load an action definition that sections files.
28.
/context <none|section|line>
Sets the ´context typeµ to ´no contextµ, ´use sections as contextµ,
or ´use lines as contextµ. Context is only used to display results on the Results panel in PowerGREP or when
saving results using the
/save
parameter.
29.
/contextextra <context|lines> <before> <after>
Tells PowerGREP how many blocks of
context or how many lines of context to show before and after each match, in addition to the block of
context that contains the match. E.g.
/contextextra lines 2 3
shows 2 lines before and 3 lines after. If
you omit the ´contextµ or ´linesµ parameter after
/contextextra
, then ´contextµ is implied when using
sections as context, and ´linesµ is implied when using lines as context. Both the before and after numbers are
required. This parameter is ignored when using
/context none
.
30.
/target
<same|"copy
modified"|"copy
all"|none|single|move|delete|replacement|placeholders> <"single folder"|"folder
tree"|archive|"numbered archive"|placeholders> <location>
Sets the target options on the
Action panel. This parameter must be followed by one value with of the target types listed below. If the target
type is something other than ´sameµ, ´noneµ, or ´replacementµ, then that value needs to be followed by two
more values.
The first value indicates how files are copied. When copying files, the original file will remain untouched. The
available values depends on the action type. Values with spaces need to be kept together with double quotes.
same = Do not copy files but change the file searched through. Do not specify any destination type or
location. (search; collect data; search-and-replace; search-and-delete)
´copy modifiedµ = Copy files in which matches have been found. (search; collect data; list files; rename files;
search-and-replace; search-and-delete)
´copy allµ = Copy all files searched through. (search-and-replace; search-and-delete)
none = Do not save results. Do not specify any destination type or location. (list files; simple search; search;
collect data; list files)
single = Save results to single file. (search; collect data; list files; merge files)
53
245
move = Move matching files (list files; rename files)
delete = Delete matching files. Do not specify any destination type or location. (list files)
replacement = Use replacement text as target (merge files; split files)
placeholders = Use path placeholders. Do not specify any destination type or location. The second value
must also be ´placeholdersµ and the third value must be the path using path placeholders. (search; collect
data; merge files)
The second value indicates the destination type for copied files:
´single folderµ = Place all target files into a single folder.
´folder treeµ = Place target files into a folder tree.
archive = Place target files into an archive.
´numbered archiveµ = Place target files into a numbered archive.
placeholders = Use path placeholders
The third value indicates the actual location. It must specify the full path to a folder, a file, an archive or use
path placeholders, depending on the destination type in the second parameter.
31.
/backup
<none|"single
bak"|"single
tilde"|"multi
bak"|"multi
name"|same|placeholders|history> <"same folder"|subfolder|"single folder"|"folder
tree"|archive|"numbered archive"> <location>
Sets the backup options on the Action panel. This
parameter must be followed by one value with of the backup types listed below. If the backup type is
something other than ´noneµ or ´historyµ, then that value needs to be followed by two more values.
The first value indicates the type of backup to create. Values with spaces need to be kept together with
double quotes.
none = Do not create backup files. Do not specify any destination type or location.
´single bakµ = Single backup appending .bak extension
´single tildeµ = Single backup with .~* extension
´multi bakµ = Multi backup appending .bak, .bak2, ... extensions
´multi nameµ = Multi backup prepending "Backup X of ..."
same = Backup with same file name as original file (destination cannot be the same folder)
placeholders = Use path placeholders. The second parameter must be specified but its value is ignored. The
third parameter must specify the path using path placeholders.
history = Hidden __history folder. Do not specify any destination type or location.
The second value indicates the destination type of the backup files:
´same folderµ = Same folder as original. Do not specify a location.
subfolder = Place all backup files into a specific subfolder of the folders holding the original files. Specify the
name of a subfolder as the location.
´single folderµ = Place all backup files into a single folder. Specify the full path to a folder as the location.
´folder treeµ = Place backup files into a folder tree. Specify the full path to a folder as the location.
archive = Place backup files into an archive. Specify the full path to an archive file as the location.
´numbered archiveµ = Place backup files into a numbered archive. Specify the full path to an archive file as
the location.
The third value indicates the actual location, either a folder, archive file or a path using path placeholders.
32.
/optbinary <0|1>
Sets the option ´search through binary filesµ.
33.
/optarchives <0|1>
Sets the option ´search through archivesµ.
Documents you may be interested
Documents you may be interested