.edit

.edit /<search_expression>/<replace_expression>/ [<relative_path>/]file [file ...]

Use the .edit command to search and replace text strings in one or more files. The .edit command replaces the first instance of the string (search_expression) on each and every line in each file specified. Files are assumed to reside in the step's working directory unless you specify a relative path.

The .edit command implements standard POSIX regular expressions for matching and replacement, including the use of () substring selection and \N substitution in the replacement pattern.

The .edit command uses POSIX Extended Regular Expression syntax by default. If the agent has been compiled with Perl Compatible Regular Expression support, then the substitution expression may be followed with a "p" character to specify PCRE syntax.

Using backslash as an escape character requires different handling depending on the operating system on the agent host.

  • On UNIX and Linux the expression is interpreted twice by the agent processing, so use four backslashes to represent one backslash. For example, use four backslashes and a period to match a literal period character.
    \\\\.
  • On Windows, only two backslashes are required to match the same literal period.
    \\.

You cannot escape delimiters. In cases where that seems desirable, the correct approach is to use an alternate delimiter character. Example: you have a file abc.txt that contains only the characters abc. You want to replace it with the string a/c:

  • Wrong - in these cases the string remains unchanged, because the delimiter character takes precedence over escape characters.
    .edit /abc/a\/c/ abc.txt
    .edit /abc/a\\/c/ abc.txt
    .edit /abc/a\\\\/c/ abc.txt
  • Right - changing the delimiter character allows a/c to be substituted.
    .edit "abc"a/c" abc.text
Note: You must explicitly list one or more file names, without wildcards.
Example: The following command replaces strings such as winXPdriver and win2000driver in the file called drivermakefile.
.edit /win.*driver/linuxdriver/ drivermakefile
The .edit command is similar to the .strsub command; differences include:
  • The .strsub command is faster than .edit when performing replacements in large text files or many files.
  • The .edit command can perform regular expression searches and replaces.
  • The .edit command replaces the first instance only of the string (search_expression) on each and every line in each file.
  • The .strsub command replaces every instance of the string (source) on each and every line in each file.