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