.strsub

.strsub <source> <replacement> file [file ...]

Use the .strsub command to perform basic string replacement in one or more text files. The system scans the target files for the <source> string; where a match is found, the system replaces the <source> string with the <replacement>. The .strsub command replaces every instance of the string (source) on each and every line in each file.

The .strsub command works across operating systems, without depending on any specific commands being available on the server.

To replace a string _VERSION_ in a file about.c, use a command such as:
.strsub _VERSION_ 2.34 about.c
You must specify one or more filenames exactly, without using wildcards. For example, a command like the following fails:
.strsub _VERSION_ 2.34 *.txt
However, you can use variables in the command, so a command such as the following works if the VERSION and FILENAME variables have been defined in the environment.
.strsub _VERSION_ ${VERSION} ${FILENAME}
Note: Use spaces to separate parameters in the command.
The .strsub command is similar to the .edit command; their 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 only the first instance 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.

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 indicate that PCRE syntax should be used, instead).

In both cases, the expression is interpreted twice by the agent processing. Therefore four backslashes should be used anywhere that a single backslash would normally be used. For example:
Four slashes escape a literal period:
\\\\.
Alternatively, you can use the /x flag to suppress backslashes:
.strsub/x