2.0;chpat (change_pattern), revision 2.0, 87/03/20
CHPAT (CHANGE_PATTERN) -- Replace pattern in text file.
usage: CHPAT [-A|-X] [-L] [-O] [pathname...] [-OUT [pathname]] [-P] [pat...]
from_pattern [to_expr]
FORMAT
CHPAT [options] [pathname ...] [-P] [pat ...] from_pattern [to_expression]
CHPAT copies every line from its input files to its output files, globally
substituting the text replacement pattern "to_expression" for each occurrence
of "from_pattern" in those lines designated by the "pat" argument(s) and any
options.
Refer to the descriptions of the ED (EDIT), FPAT (FIND_PATTERN), and EDSTR
(EDIT_STREAM) commands for related information.
ARGUMENTS
pathname
(optional) Specify name of file to be searched. Multiple pathnames
and wildcarding are permitted.
Default if omitted: search standard input.
from_pattern
(required) Specify target text string (a regular expression) for
substitution or deletion. If the string includes the
characters % $ [ ] { } ! * or any other Shell special
characters, enclose it in quotes to avoid unpredictable
results. If the 'pathname' argument is present, precede
this argument (or the 'pat' argument, if present) with "-P"
to separate the pathname(s) from the regular expressions on
the command line.
to_expression
(optional) Specify replacement string. If no replacement is
specified, the 'from_pattern' string will be deleted. If
regular expressions defining a range of text ('pat'
argument) are present, you must use a literally null
'to_expression' ("") to delete 'from_pattern'.
pat
(optional) Specify range of text for which the substitution is to
apply, in the form of a regular expression. Multiple
expressions separated by blanks are permitted. Unless
modified by options, any line of text matching any pattern
is replaced and all lines, changed or not, are written to
output. If the 'pathname' argument is present, precede
this argument with "-P" to separate the pathname(s) from
the regular expressions on the command line.
Default if omitted: use 'from_pattern' to select matching
lines.
OPTIONS
-a Select only lines that match all of the leading
expressions, in any order.
-x Select only lines that match none of the leading
expressions.
-o Write only the selected lines to standard output. By
default, CHPAT writes all lines to output.
-l List name(s) of input file(s) on output file(s) as the
input file(s) are searched.
-out pathname
Specify name of output file. Note that this option is
position dependent and must follow the input pathname if
both are specified. Pathname may be derived from the input
file name. If this option is omitted, output is written to
standard output.
EXAMPLES
1. $ chpat foo bar
Changes all occurrences of 'foo' in standard input to 'bar'
and writes the results to standard output.
2. $ chpat '%This' " *" ' '
In lines starting with 'This', it changes all occurrences
of multiple spaces to a single space.
3. $ chpat '%This' '%That' " *" ' '
Like 2., but works on lines starting with either 'This' or
'That'.
4. $ chpat -a '%when' 'only$' ';' ':'
In lines that start with 'when' and end with 'only', change
all semicolons to colons.
5. $ chpat -x not none some all
In lines that do not contain either 'not' or 'none', change
all instances of 'some' to 'all'.
6. $ chpat erase
Delete (replace with nothing) all occurrences of 'erase'.
Exactly the same effect can be obtained with:
$ chpat erase ''
7. $ chpat -o other_opts pat... fr_pat to_pat
Is exactly the same as
$ fpat pat... | chpat other_opts fr_pat to_pat
8. $ chpat ?*.pas -out =.new -p "if x = y" "if (x = y)"
Change all occurrences of the string "if x = y"
to "if (x = y)" in all Pascal source files (files ending with
'.pas') and put the output for 'X.pas' in 'X.pas.new'.
RELATED TOPICS
More information is available. Type:
- HELP PATTERNS
for details about regular expression syntax and usage.