2.0; chpat (change_pattern), revision 2.0, 81/07/01.
CHPAT (CHANGE_PATTERN) -- Replace pattern in text file.
usage: CHPAT [-A|-X] [-L] [-O] [-OUT [pathname]] [pathname... -P]
[from_pattern | [pat...] from_pattern to_expr]
FORMAT
CHPAT [options] [pathname ... -P] [from_pattern | pat ...]
from_pattern [to_expression]
CHPAT copies every line from its input files to its output files,
globally substituting the text replacement pattern "to_expr" for
each occurrence of "fr_pat" in those lines which match according
to the "pat" arguments and the options flags.
Refer to the help files 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. If this argument is present,
it must be followed by "-P" to separate the pathname(s)
from the search patterns on the command line.
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.
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.
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. 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 occurences 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)"
will 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, say, 'X.pas' in 'X.pas.new'.
RELATED TOPICS
More information is available. Type:
- HELP PATTERNS
for details about regular expression syntax and usage.