1BSD/man6/gres.6

.th GRES I 6/12/75
.sh NAME
gres \*- substitute for patterns throughout a file or files
.sh SYNOPSIS
.bd "gres"
[
.bd \*-g
] [
.bd \*-v
] [
.bd \*-f
patternfile ] ... [ [
.bd \*-e
] re1 re2 rhs ] ... [ file ] ...
.sh DESCRIPTION
.it Gres
copies the input
.it files
(standard input default)
to the standard output, performing
substitutions for instances of one or more
regular expressions.
The intention is to simulate a series of
editor commands of the form:
.sp
	g/re1/s/re2/rhs/
.sp
on one or more files (see
.it ed
(I)).
.s3
A
.bd \*-e
flag says that the next three arguments are
to be used as an
.it re1,
.it re2,
and
.it rhs.
.s3
A
.bd \*-f
flag says that the next argument is a
.it patternfile,
in which the first line is an
.it re1,
the second an
.it re2,
and the third an
.it rhs.
Successive groups of three lines are interpreted similarly.
.s3
The
.bd \*-e
and
.bd \*-f
groups of arguments may be intermixed in any order.
The order of the
simulated
.it g
commands is the order in which the program sees the
pattern-triples; that is, the order in the
command line, and within a
.bd \*-f
group, the order in the pattern-file.
.s3
If no
.bd \*-e
or
.bd \*-f
flags are given, the first three arguments
are used as
.it re1,
.it re2,
and
.it rhs.
.s3
When the first argument not in the scope of a flag is encountered,
it and all succeeding arguments are taken as input files.
For each line of input, an attempt is made to match the first
.it re1.
If the attempt succeeds, an attempt is made to replace
a match or matches of
.it re2
by
.it rhs.
Whether or not either attempt succeeds, the line
as it exists after the action of the first
.it "re1, re2,"
and
.it rhs
is used as input to the next
.it "re1, re2,"
and
.it rhs,
etc.
.s3
Normally only the first match of an
.it re2
in a line is replaced;
but with a
.bd \*-g
all instances of matches to
.it re2
are replaced by
.it rhs.
.s3
The
.bd \*-v
flag causes the substitution to be attempted
only on lines which do
.it not
contain matches of
.it re1.
.sh FILES
.sh "SEE ALSO"
ed (I)
.sh DIAGNOSTICS
.sh BUGS