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 between 0 and 9. 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-free agrep program. 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 the GREP_COLOR environment 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 -v was 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 is 1.
  • -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 is 0. 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 -d is 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 Β© 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