1.\" $NetBSD: agrep.1,v 1.1 2011/11/05 22:39:13 christos Exp $ 2.Dd November 21, 2004 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 D Ar num , Fl Fl delete-cost= Ns Ar num 55Set cost of missing characters to 56.Ar num . 57.It Fl I Ar num , Fl Fl insert-cost= Ns Ar num 58Set cost of extra characters to 59.Ar num . 60.It Fl S Ar num , Fl Fl substitue-cost= Ns Ar num 61Set cost of incorrect characters to 62.Ar num . 63Note that a deletion (a missing character) and an insertion (an extra 64character) together constitute a substituted character, but the cost 65will be the that of a deletion and an insertion added together. 66Thus, if the const of a substitution is set to be larger than the 67sum of the costs of deletion and insertion, direct substitutions 68will never be done. 69.It Fl E num , Fl Fl max-errors= Ns Ar num 70Select records that have at most 71.Ar num 72errors. 73.It Fl Ns Ar # 74Select records that have at most 75.Ar # 76errors 77.Ar ( # 78is a digit between 0 and 9). 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 v , Fl Fl invert-match 97Select non-matching records instead of matching records. 98.It Fl V , Fl Fl version 99Print version information and exit. 100.It Fl y , Fl Fl nothing 101Does nothing. 102This options exists only for compatibility with the 103non-free agrep program. 104.It Fl Fl help 105Display a brief help message and exit. 106.El 107.Ss Output control 108.Bl -tag -width 10n 109.It Fl B , Fl Fl best-match 110Only output the best matching records, that is, the records with the 111lowest cost. 112This is currently implemented by making two passes over 113the input files and cannot be used when reading from standard input. 114.It Fl Fl color , Fl Fl colour 115Highlight the matching strings in the output with a color marker. 116The color string is taken from the 117.Ev GREP_COLOR 118environment variable. 119The default color is red. 120.It Fl c , Fl Fl count 121Only print a count of matching records per each input file, 122suppressing normal output. 123.It Fl h , Fl Fl no-filename 124Suppress the prefixing filename on output when multiple files are 125searched. 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 l , Fl Fl files-with-matches 130Only print the name of each input file which contains at least one 131match, suppressing normal output. 132The scanning for each file will stop on the first match. 133.It Fl n , Fl Fl record-number 134Prefix each output record with its sequence number in the input file. 135The number of the first record is 1. 136.It Fl q , Fl Fl quiet , Fl Fl silent 137Do not write anything to standard output. 138Exit immediately with zero exit status if a match is found. 139.It Fl s , Fl Fl show-cost 140Print match cost with output. 141.It Fl Fl show-position 142Prefix each output record with the start and end offset of the first 143match within the record. 144The offset of the first character of the record is 0. 145The end position is given as the offset of the first 146character after the match. 147.It Fl M , Fl Fl delimiter-after 148By default, the record delimiter is the newline character and is 149output after the matching record. 150If 151.Fl d 152is used, the record delimiter will be output before the matching 153record. 154This option causes the delimiter to be output after the 155matching record. 156.El 157.Pp 158With no 159.Ar file , 160or when 161.Ar file 162is 163.Dq - , 164.Nm 165reads standard input. 166If less than two 167.Ar files 168are given 169.Fl h 170is assumed, otherwise 171.Fl H 172is the default. 173.Sh EXAMPLES 174.Dl agrep \-2 optimize foo.txt 175outputs all lines in file 176.Pa foo.txt 177that match 178.Dq optimize 179within two errors. 180E.g. lines which contain 181.Dq optimise , 182.Dq optmise , 183and 184.Dq opitmize 185all match. 186.Sh DIAGNOSTICS 187Exit status is 0 if a match is found, 1 for no match, and 2 if there 188were errors. 189If 190.Fl E 191or 192.Fl Ns Ar # 193is not specified, only exact matches are selected. 194.Pp 195.Ar pattern 196is a POSIX extended regular expression (ERE) with the TRE extensions. 197.Sh REPORTING BUGS 198Report bugs to the TRE mailing list 199.Aq tre-general@lists.laurikari.net . 200.Sh COPYRIGHT 201Copyright \(co 2002-2004 Ville Laurikari. 202.Pp 203This is free software, and comes with ABSOLUTELY NO WARRANTY. 204You are welcome to redistribute this software under certain 205conditions; see the source for the full license text. 206