GREP(1)
πΈ GREP(1) β the perl grep, bestie edition πΈ
okay so real talk: this is grep from User Contributed Perl Documentation, and she's not your grandma's grep. She's a Perl program, she's iconic, and she's about to make searching files feel like a whole personality trait. π
β¨ NAME β¨
grep β search for regular expressions and print π
π¦ SYNOPSIS π¦
grep [-acFgHhIiLlnqRrsTuvwxZ] [-e pattern] [-A NUM] [-B NUM] [-C NUM]
[-m NUM] [-f pattern-file] [pattern] [file ...]
π DESCRIPTION π
grep searches for lines in files that satisfy the criteria specified by the user-supplied patterns. and because this grep is a Perl program, you get full access to Perl's rich regular expression engine. like, the whole engine. see perlre. no cap, it's giving main character energy. π₯
The first argument after the options (assuming you didn't specify the -e option or the -f option) is taken as pattern. If you don't supply a list of file or directory names to search, tcgrep will attempt to search its standard input. π«Ά
With no arguments, grep will output its option list and exit. (she's just showing off at that point, honestly.)
π OPTIONS π
The following options are accepted:
-m NUMβ Display a maximum ofNUMmatches per file.-A NUMβ DisplayNUMlines of context after each matching line.-aβ List matching lines from binary files as if they were plain text files.-B NUMβ DisplayNUMlines of context before each matching line.-C NUMβ DisplayNUMlines of context surrounding each matching line.-cβ Output only the count of the matching lines.-epattern β Treat pattern as a pattern. This option is most useful when pattern starts with a-and you want to avoid confusing the option parser. (honestly the option parser is doing her best π) The-foption supercedes the-eoption.-Fβ fgrep mode. Disable regular expressions and perform Boyer-Moore searches. (Whether it lives up to the 'f' in fgrep is another issue.) π-fpattern-file β Treat pattern-file as a newline-separated list of patterns to use as search criteria. the-foption supercedes the-eoption.-gβ Highlight matches. This option causesgrepto attempt to use your terminal's stand-out (emboldening) functionality to highlight those portions of each matching line that actually triggered the match. This feature is very similar to the way theless(1)pager highlights matches. See also-u. β¨-Hβ Always include filename headers for matching lines.-hβ Hide filenames. Only print matching lines.-Iβ Ignore binary files.-iβ Ignore case while matching. This means, for example, that the pattern"unix"would match"unix"as well as"UniX"(plus the other fourteen possible capitalizations). This corresponds to the/iPerl regular expression switch. Seeperlre. π-Lβ List files which do no match any pattern. This option takes precedence over-l.-lβ List files containing matches. This option tellsgrepnot to print any matches but only the names of the files containing matches. This option implies the-1option.-nβ Number lines. Before outputting a given match,grepwill first output its line corresponding to the value of the Perl magic scalar$.(whose documentation is inperlvar).-sβ Suppress diagnostic messages to the standard error.-Rand-rβ Recursively scan directories. This option causesgrepto descend directories in a left-first, depth-first manner and search for matches in the files of each directory it encounters. The presence of-rimplies a file argument of., the current directory, if you don't provide filenames on the command line. See"EXAMPLES". π¦-qβ Quiet mode. Do not write to the standard output. This option would be useful from a shell script, for example, if you are only interested in whether or not there exists a match for a pattern.-Tβ Trace files as processed. This causesgrepto send diagnostic messages to the standard error when skipping symbolic links to directories, when skipping directories because you didn't give the-rswitch, when skipping non-plain files (see"-f"inperlfunc), when skipping non-text files (see"-T"inperlfunc), and when opening a file for searching. (she's narrating her own life, honestly relatable π)-uβ Underline matches. This option causesgrepto attempt to use your terminal's underline functionality to underline those portions of each matching line that actually triggered the match. See also-H.-vβ Invert the sense of the match, i.e. print those lines that do not match. When using this option in conjunction with-f, keep in mind that the entire set of patterns are grouped together in one pattern for the purposes of negation. See"EXAMPLES".-wβ Matches must start and end at word boundaries. This is currently implemented by surrounding each pattern with a pair of"\b", the Perl regular expression word boundary metasequence. Seeperlrefor the precise definition of"\b".-xβ Exact matches only. The pattern must match the entire line.-Zβ Operate in zgrep mode. Compressed file arguments are decompressed before searching for the pattern. π
π ENVIRONMENT π
The TERM variable is used for output formatting in the -g and -u options.
π EXAMPLES π
Search all files under /etc/init.d for a particular pattern:
% grep -r tcgrep /etc/init.d
Use of -v and -f options in conjunction with one another:
% cat fruits
pomme
banane
poire
% cat pats
pomme
poire
% grep -vf pats fruits
banane
like?? banane is the only one left. she ate. π
π§ TODO π§
- Add more cool examples. :-)
- Perhaps allow the user to provide an exclusion pattern for skipping over files whose names match the pattern.
(manifesting the exclusion pattern option for us fr fr π)
β AUTHOR β
tcgrep was written by Tom Christiansen with updates by Greg Bacon and Paul Grassie. absolute legends, we stan. π
π COPYRIGHT and LICENSE π
Copyright (c) 1993-1999. Tom Christiansen.
This program is free and open software. You may use, copy, modify, distribute, and sell this program (and any modified variants) in any way you wish, provided you do not restrict others from doing the same.
okay that's the whole page bestie, go grep something π β this was perl v5.42.2, dated 2026-02-15, and that's the GREP(1) tea, periodt. πΈ
π¦ where this page comes from
- alpine 3.24: perl-power-tools-doc 1.053-r1 Β· GPL-2.0-or-later AND Artistic-1.0-Perl AND Artistic-2.0 AND BSD-2-Clause
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms