xref: /netbsd-src/external/bsd/tre/bin/agrep.1 (revision 2c1d82f1753d8218ca0280f13c812c6e48daa810)
1*2c1d82f1Swiz.\" $NetBSD: agrep.1,v 1.4 2016/06/10 08:03:46 wiz Exp $
2*2c1d82f1Swiz.Dd June 10, 2016
3f2a3d147Schristos.Dt AGREP 1
4f2a3d147Schristos.Os
5f2a3d147Schristos.Sh NAME
6f2a3d147Schristos.Nm agrep
7f2a3d147Schristos.Nd print lines approximately matching a pattern
8f2a3d147Schristos.Sh SYNOPSIS
9f2a3d147Schristos.Nm
10f2a3d147Schristos.Op options
11f2a3d147Schristos.Ar pattern
12f2a3d147Schristos.Op files
13f2a3d147Schristos.Sh DESCRIPTION
14f2a3d147SchristosSearches for approximate matches of
15f2a3d147Schristos.Ar pattern
16f2a3d147Schristosin each
17f2a3d147Schristos.Ar FILE
18f2a3d147Schristosor standard input.
19f2a3d147Schristos.Sh OPTIONS
20f2a3d147Schristos.Ss Regexp selection and interpretation
21f2a3d147Schristos.Bl -tag -width 10n
22f2a3d147Schristos.It Fl e Ar pattern , Fl Fl regexp= Ns Ar pattern
23f2a3d147SchristosUse
24f2a3d147Schristos.Ar PATTERN
25f2a3d147Schristosas a regular expression; useful to protect patterns beginning with
26f2a3d147Schristos.Sq - .
27f2a3d147Schristos.It Fl i , Fl Fl ignore-case
28f2a3d147SchristosIgnore case distinctions (as defined by the current locale) in
29f2a3d147Schristos.Ar pattern
30f2a3d147Schristosand input files.
31f2a3d147Schristos.It Fl k , Fl Fl literal
32f2a3d147SchristosTreat
33f2a3d147Schristos.Ar pattern
34f2a3d147Schristosas a literal string, that is, a fixed string with no special
35f2a3d147Schristoscharacters.
36f2a3d147Schristos.It Fl w , Fl Fl word-regexp
37f2a3d147SchristosForce
38f2a3d147Schristos.Ar pattern
39f2a3d147Schristosto match only whole words.
40f2a3d147SchristosA
41f2a3d147Schristos.Dq whole word
42f2a3d147Schristosis a substring which either starts at the beginning
43f2a3d147Schristosor the record or is preceded by a non-word constituent character.
44f2a3d147SchristosSimilarly, the substring must either end at the end of the record
45f2a3d147Schristosor be followed by a non-word constituent character.
46f2a3d147SchristosWord-constituent characters are alphanumerics (as
47f2a3d147Schristosdefined by the current locale) and the underscore character.
48f2a3d147SchristosNote that the non-word constituent characters
49f2a3d147Schristos.Em must
50f2a3d147Schristossurround the match; they cannot be counted as errors.
51f2a3d147Schristos.El
52f2a3d147Schristos.Ss Approximate matching settings
53f2a3d147Schristos.Bl -tag -width 10n
54eb70e354Swiz.It Fl Ns Ar #
55eb70e354SwizSelect records that have at most
56eb70e354Swiz.Ar #
57eb70e354Swizerrors
58eb70e354Swiz.Ar ( #
59eb70e354Swizis a digit between 0 and 9).
60f2a3d147Schristos.It Fl D Ar num , Fl Fl delete-cost= Ns Ar num
61f2a3d147SchristosSet cost of missing characters to
62f2a3d147Schristos.Ar num .
63eb70e354Swiz.It Fl E num , Fl Fl max-errors= Ns Ar num
64eb70e354SwizSelect records that have at most
65eb70e354Swiz.Ar num
66eb70e354Swizerrors.
67f2a3d147Schristos.It Fl I Ar num , Fl Fl insert-cost= Ns Ar num
68f2a3d147SchristosSet cost of extra characters to
69f2a3d147Schristos.Ar num .
70f2a3d147Schristos.It Fl S Ar num , Fl Fl substitue-cost= Ns Ar num
71f2a3d147SchristosSet cost of incorrect characters to
72f2a3d147Schristos.Ar num .
73f2a3d147SchristosNote that a deletion (a missing character) and an insertion (an extra
74f2a3d147Schristoscharacter) together constitute a substituted character, but the cost
75f2a3d147Schristoswill be the that of a deletion and an insertion added together.
76f2a3d147SchristosThus, if the const of a substitution is set to be larger than the
77f2a3d147Schristossum of the costs of deletion and insertion, direct substitutions
78f2a3d147Schristoswill never be done.
79f2a3d147Schristos.El
80f2a3d147Schristos.Ss Miscellaneous
81f2a3d147Schristos.Bl -tag -width 10n
82f2a3d147Schristos.It Fl d pattern , Fl Fl delimiter= Ns Ar pattern
83f2a3d147SchristosSet the record delimiter regular expression to
84f2a3d147Schristos.Ar pattern .
85f2a3d147SchristosThe text between two delimiters, before the first delimiter, and after
86f2a3d147Schristosthe last delimiter is considered to be a record.
87f2a3d147SchristosThe default record
88f2a3d147Schristosdelimiter is the regexp
89f2a3d147Schristos.Dq \en ,
90f2a3d147Schristosso by default a record is a line.
91f2a3d147Schristos.Ar pattern
92f2a3d147Schristoscan be any regular expression that does not match the empty string.
93f2a3d147SchristosFor example, using
94f2a3d147Schristos.Fl d Ar \"^From \"
95f2a3d147Schristosdefines mail messages as records in a Mailbox format file.
96eb70e354Swiz.It Fl Fl help
97eb70e354SwizDisplay a brief help message and exit.
983ac25dcbSagc.It Fl r , Fl Fl recursive
993ac25dcbSagcIf a directory is given as one of the command line arguments,
1003ac25dcbSagclook in every directory entry in the subdirectory, recursively.
101eb70e354Swiz.It Fl V , Fl Fl version
102eb70e354SwizPrint version information and exit.
103eb70e354Swiz.It Fl v , Fl Fl invert-match
104eb70e354SwizSelect non-matching records instead of matching records.
105f2a3d147Schristos.It Fl y , Fl Fl nothing
106f2a3d147SchristosDoes nothing.
107f2a3d147SchristosThis options exists only for compatibility with the
108f2a3d147Schristosnon-free agrep program.
109f2a3d147Schristos.El
110f2a3d147Schristos.Ss Output control
111f2a3d147Schristos.Bl -tag -width 10n
112f2a3d147Schristos.It Fl B , Fl Fl best-match
113f2a3d147SchristosOnly output the best matching records, that is, the records with the
114f2a3d147Schristoslowest cost.
115f2a3d147SchristosThis is currently implemented by making two passes over
116f2a3d147Schristosthe input files and cannot be used when reading from standard input.
117f2a3d147Schristos.It Fl Fl color , Fl Fl colour
118f2a3d147SchristosHighlight the matching strings in the output with a color marker.
119f2a3d147SchristosThe color string is taken from the
120f2a3d147Schristos.Ev GREP_COLOR
121f2a3d147Schristosenvironment variable.
122f2a3d147SchristosThe default color is red.
123f2a3d147Schristos.It Fl c , Fl Fl count
124f2a3d147SchristosOnly print a count of matching records per each input file,
125f2a3d147Schristossuppressing normal output.
126f2a3d147Schristos.It Fl H , Fl Fl with-filename
127f2a3d147SchristosPrefix each output record with the name of the input file where the
128f2a3d147Schristosrecord was read from.
129eb70e354Swiz.It Fl h , Fl Fl no-filename
130eb70e354SwizSuppress the prefixing filename on output when multiple files are
131eb70e354Swizsearched.
132f2a3d147Schristos.It Fl l , Fl Fl files-with-matches
133f2a3d147SchristosOnly print the name of each input file which contains at least one
134f2a3d147Schristosmatch, suppressing normal output.
135f2a3d147SchristosThe scanning for each file will stop on the first match.
136eb70e354Swiz.It Fl M , Fl Fl delimiter-after
137eb70e354SwizBy default, the record delimiter is the newline character and is
138eb70e354Swizoutput after the matching record.
139eb70e354SwizIf
140eb70e354Swiz.Fl d
141eb70e354Swizis used, the record delimiter will be output before the matching
142eb70e354Swizrecord.
143eb70e354SwizThis option causes the delimiter to be output after the
144eb70e354Swizmatching record.
145f2a3d147Schristos.It Fl n , Fl Fl record-number
146f2a3d147SchristosPrefix each output record with its sequence number in the input file.
147f2a3d147SchristosThe number of the first record is 1.
148f2a3d147Schristos.It Fl q , Fl Fl quiet , Fl Fl silent
149f2a3d147SchristosDo not write anything to standard output.
150f2a3d147SchristosExit immediately with zero exit status if a match is found.
151f2a3d147Schristos.It Fl s , Fl Fl show-cost
152f2a3d147SchristosPrint match cost with output.
153f2a3d147Schristos.It Fl Fl show-position
154f2a3d147SchristosPrefix each output record with the start and end offset of the first
155f2a3d147Schristosmatch within the record.
156f2a3d147SchristosThe offset of the first character of the record is 0.
157f2a3d147SchristosThe end position is given as the offset of the first
158f2a3d147Schristoscharacter after the match.
159f2a3d147Schristos.El
160f2a3d147Schristos.Pp
161f2a3d147SchristosWith no
162f2a3d147Schristos.Ar file ,
163f2a3d147Schristosor when
164f2a3d147Schristos.Ar file
165f2a3d147Schristosis
166f2a3d147Schristos.Dq - ,
167f2a3d147Schristos.Nm
168f2a3d147Schristosreads standard input.
169f2a3d147SchristosIf less than two
170f2a3d147Schristos.Ar files
171f2a3d147Schristosare given
172f2a3d147Schristos.Fl h
173f2a3d147Schristosis assumed, otherwise
174f2a3d147Schristos.Fl H
175f2a3d147Schristosis the default.
176f2a3d147Schristos.Sh EXAMPLES
177f2a3d147Schristos.Dl agrep \-2 optimize foo.txt
178f2a3d147Schristosoutputs all lines in file
179f2a3d147Schristos.Pa foo.txt
180f2a3d147Schristosthat match
181f2a3d147Schristos.Dq optimize
182f2a3d147Schristoswithin two errors.
183f2a3d147SchristosE.g. lines which contain
184f2a3d147Schristos.Dq optimise ,
185f2a3d147Schristos.Dq optmise ,
186f2a3d147Schristosand
187f2a3d147Schristos.Dq opitmize
188f2a3d147Schristosall match.
189f2a3d147Schristos.Sh DIAGNOSTICS
190f2a3d147SchristosExit status is 0 if a match is found, 1 for no match, and 2 if there
191f2a3d147Schristoswere errors.
192f2a3d147SchristosIf
193f2a3d147Schristos.Fl E
194f2a3d147Schristosor
195f2a3d147Schristos.Fl Ns Ar #
196f2a3d147Schristosis not specified, only exact matches are selected.
197f2a3d147Schristos.Pp
198f2a3d147Schristos.Ar pattern
199f2a3d147Schristosis a POSIX extended regular expression (ERE) with the TRE extensions.
200f2a3d147Schristos.Sh REPORTING BUGS
201f2a3d147SchristosReport bugs to the TRE mailing list
202eb70e354Swiz.Aq Mt tre-general@lists.laurikari.net .
203f2a3d147Schristos.Sh COPYRIGHT
204f2a3d147SchristosCopyright \(co 2002-2004 Ville Laurikari.
205f2a3d147Schristos.Pp
206f2a3d147SchristosThis is free software, and comes with ABSOLUTELY NO WARRANTY.
207f2a3d147SchristosYou are welcome to redistribute this software under certain
208f2a3d147Schristosconditions; see the source for the full license text.
209