10.0;chpat (change_pattern), revision 1.0, 88/01/21
chpat (change_pattern) -- Replace pattern in text file.
usage: chpat [-a|-x] [-l] [-o]
[pathname...]
[-out [pathname]]
[-p] [pat...]
from_pattern [to_expr]
DESCRIPTION
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 you do not specify a
replacement, the from_pattern is 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 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 you
specify both. Pathname may be derived from the input
filename. If this option is omitted, output is written to
standard output.
EXAMPLES
Changes all occurrences of foo in standard input to bar and writes the
results to standard output.
$ chpat foo bar
In lines starting with This, it changes all occurrences of multiple
spaces to a single space.
$ chpat '%This' " *" ' '
Works on lines starting with either This or That.
$ chpat '%This' '%That' " *" ' '
In lines that start with when and end with only, change all semicolons
to colons.
$ chpat -a '%when' 'only$' ';' ':'
In lines that do not contain either not or none, change all instances of
some to all.
$ chpat -x not none some all
Delete (replace with nothing) all occurrences of erase.
$ chpat erase
Exactly the same effect can be obtained with
$ chpat erase ''
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.
$ chpat ?*.pas -out =.new -p "if x = y" "if (x = y)"
SEE ALSO
More information is available. Type
help patterns For details about regular expression syntax and usage