REPLACETEXT
— Replace strings
in text from a file.
Syntax:
REPLACETEXT
/A:
attribs /C /CP:
n /H /N /P /R:
from:
to /S /W /X:
from:
to
filename…
/A: attribs | attributes mask; valid flags are -ACEHIORS |
/C | replace character escapes (affects following /R: and /X: ) |
/CP: n | interpret non-Unicode input text using code page n |
/H | display filenames |
/N | disable features |
/P | page output |
/R: from: to | specify old and replacement text |
/S | search in subdirectories for matching files |
/W | whole words only (affects following /R: and /X: ) |
/X: from: to | specify old and replacement text (do not auto-capitalize) |
… | Range options are also supported. |
If standard input (stdin) is redirected, REPLACETEXT
will read
from stdin before any filenames specified on the
command line. If no filenames are specified, then
REPLACETEXT
will read from stdin whether it is redirected or not.
Filenames may include wildcards and directory aliases. You can search into
subdirectories for matching files with /S
. @File lists and
internet files are supported. You may also specify CLIP:
to read
from the clipboard.
If you want to pipe to REPLACETEXT
, remember that pipes open a
new shell. To pipe to a plugin command, you must either ensure that the plugin
is loaded in the transient shell, e.g. by installing the
.DLL in the shell’s .DLL
directory; or else use temporary files or an in-process pipe.
Use /R:
or /X:
to specify the strings to search for (from)
and to substitute (to). You must have at least
one of these; you may add as many as you like. The text from each matching file
will be dumped to stdout, with every occurrence of from
replaced with the corresponding to string. If you
give a from string without a matching
to, then matching strings will simply be omitted
from the output. The difference between the two options is that /R:
automatically capitalizes the to string to match
the from text which it replaces, but /X:
does not. The rules for /R:
are simple:
/W
only affects those /R:
and /X:
options which follow it on the command line. /W
prevents matching text which immediately follows or immediately precedes a
letter or digit.
/C
only affects those /R:
and /X:
options which follow it on the command line. /C
expands character escapes of the form \
nnn
(decimal) or \X
xx (hexadecimal) in both
the from and to text.
Use this option to embed troublesome characters. For example, you could use
/C /R:\x22:
to strip double-quote marks from a file.
/NB | do not write a Byte Order Mark |
/NC | disable highlight |
/ND | do not search into hidden directories; only useful with /S |
/NF | suppress the file-not-found error |
/NJ | do not search into junctions; only useful with /S |
/NZ | do not search into system directories; only useful with /S |
You can combine these, e.g. /NDJ
.
replacetext "Engine Summer.txt" /w /r:winter:autumn /r:but:yet