agrep(1)
π¦ agrep(1) β the General Commands Manual page, but make it a group chat π¦
okay bestie so picture this: you have a pattern but you're not being picky about it. like you want the vibe of the match, not a perfectionist. that's agrep. it lives in the General Commands Manual and it is lowkey iconic π
β¨ NAME β¨
agrep β print lines that approximately match a pattern. yes, approximately. it's giving "close enough bestie" π«Ά
β¨ SYNOPSIS β¨
agrep [OPTION]... PATTERN [FILE]...
πΈ DESCRIPTION πΈ
so it goes looking for approximate matches of PATTERN in each FILE, or in standard input if you don't hand it any files. no cap.
Example, and this one is a classic:
agrep -2 optimize foo.txt
that outputs all the lines in file foo.txt that match "optimize" within two errors. so like, lines containing "optimise", "optmise", and "opitmize" all match. which is honestly so forgiving of them. main character energy from a search tool fr fr π₯
π OPTIONS π
π Regexp selection and interpretation:
-e PATTERN,--regexp=PATTERNβ use PATTERN as a regular expression. super useful for protecting patterns that start with-, because otherwise the shell thinks you're being weird about a flag.-i,--ignore-caseβ ignore case distinctions (as defined by the current locale) in PATTERN and in the input files. uppercase girlies and lowercase girlies, united π«Ά-k,--literalβ treat PATTERN as a literal string, aka a fixed string with no special characters. no regex nonsense, just vibes.-w,--word-regexpβ force PATTERN to match only whole words. and a "whole word" means a substring which either starts at the beginning of the record or is preceded by a non-word constituent character. similarly, the substring must either end at the end of the record or be followed by a non-word constituent character. word-constituent characters are alphanumerics (as defined by the current locale) and the underscore character_. > β οΈ note that the non-word constituent characters must surround the match β they cannot be counted as errors. periodt.
π Approximate matching settings:
-D NUM,--delete-cost=NUMβ set the cost of missing characters to NUM.-I NUM,--insert-cost=NUMβ set the cost of extra characters to NUM.-S NUM,--substitute-cost=NUMβ set the cost of incorrect characters to NUM. > π¨ note that a deletion (a missing character) and an insertion (an extra character) together constitute a substituted character, but the cost will be that of a deletion and an insertion added together. so if the cost of a substitution is set to be larger than the sum of the costs of deletion and insertion, direct substitutions will never be done. the way the math just decides that for you π-E NUM,--max-errors=NUMβ select records that have at most NUM errors.-#β select records that have at most#errors, where#is a digit between0and9. yes you literally just type the number. no flag letter, just the digit. iykyk β¨
π Miscellaneous:
-d PATTERN,--delimiter=PATTERNβ set the record delimiter regular expression to PATTERN. the text between two delimiters, before the first delimiter, and after the last delimiter is considered to be a record. the default record delimiter is the regexp"\n", so by default a record is a line. PATTERN can be any regular expression that does not match the empty string. for example, using-d "^From "defines mail messages as records in a Mailbox format file. obsessed with how that works π-v,--invert-matchβ select non-matching records instead of matching records. the contrarian option. we love her.-V,--versionβ print version information and exit.-y,--nothingβ does nothing. this option exists only for compatibility with the non-freeagrepprogram. she's literally just standing there. respect π--helpβ display a brief help message and exit.
π Output control:
-B,--best-matchβ only output the best matching records, that is, the records with the lowest cost. > β οΈ this is currently implemented by making two passes over the input files and cannot be used when reading from standard input. two passes, bestie. she needs a second look.--color,--colourβ highlight the matching strings in the output with a color marker. the color string is taken from theGREP_COLORenvironment variable. the default color is red. πΉ (and yes, both spellings, we're inclusive here)-c,--countβ only print a count of matching records per each input file, suppressing normal output.-h,--no-filenameβ suppress the prefixing filename on output when multiple files are searched.-H,--with-filenameβ prefix each output record with the name of the input file where the record was read from.-l,--files-with-matchesβ only print the name of each input file which contains at least one match, suppressing normal output. the scanning for each file will stop on the first match. efficiency queen π-m NUM,--max-count=NUMβ stop processing each input file after NUM matching (or non-matching if-vwas specified) lines. a negative value is interpreted as infinity, which is the default. infinity is the default, as she deserves π-n,--record-numberβ prefix each output record with its sequence number in the input file. the number of the first record is1.-q,--quiet,--silentβ do not write anything to standard output. exit immediately with zero exit status if a match is found. not a single word. silent treatment but it's a feature π€-s,--show-costβ print match cost with output.--show-positionβ prefix each output record with the start and end offset of the first match within the record. the offset of the first character of the record is0. the end position is given as the offset of the first character after the match.-M,--delimiter-afterβ by default, the record delimiter is the newline character and is output after the matching record. if-dis used, the record delimiter will be output before the matching record. this option causes the delimiter to be output after the matching record. look at her, fixing the order π«
with no FILE, or when FILE is -, it reads standard input. and if less than two FILEs are given, -h is assumed β otherwise -H is the default. so it just knows. π§
π DIAGNOSTICS π
exit status is 0 if a match is found, 1 for no match, and 2 if there were errors. and heads up: if -E or -# is not specified, only exact matches are selected. yeah. approximate matching is an opt-in lifestyle, bestie.
PATTERN is a POSIX extended regular expression (ERE) with the TRE extensions. fancy and standards-compliant, we contain multitudes β¨
π REPORTING BUGS π
report bugs to the TRE mailing list <tre-general@lists.laurikari.net>. don't be shy, they want to hear it π«Ά
π COPYRIGHT π
Copyright Β© 2002-2004 Ville Laurikari.
this is free software, and comes with ABSOLUTELY NO WARRANTY. you are welcome to redistribute this software under certain conditions; see the source for the full license text. read the source, bestie, it's right there π
and that's the whole page, no cap π this was TRE agrep 0.9.0, dated November 21, 2004 β yeah she's vintage, she's a classic, she's still slaying. mwah π β¨
π¦ where this page comes from
- arch rolling: tre 0.9.0-1 Β· custom:BSD
- fedora 43: agrep 0.9.0-2.fc43 Β· BSD-2-Clause
- fedora 44: agrep 0.9.0-3.fc44 Β· BSD-2-Clause
- nixos 26.05: tre 0.9.0
- nixpkgs unstable: tre 0.9.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms