GREP(1)

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. Because this grep is a Perl program, the user has full access to Perl's rich regular expression engine. See perlre.

The first argument after the options (assuming the user did not specify the -e option or the -f option) is taken as pattern. If the user does not 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.

OPTIONS
The following options are accepted:

-m NUM
    Display a maximum of NUM matches per file.

-A NUM
    Display NUM lines of context after each matching line.

-a  List matching lines from binary files as if they were plain text files.

-B NUM
    Display NUM lines of context before each matching line.

-C NUM
    Display NUM lines of context surrounding each matching line.

-c  Output only the count of the matching lines.

-e pattern
    Treat pattern as a pattern. This option is most useful when pattern starts with a "-" and the user wants to avoid confusing the option parser.

    The -f option supercedes the -e option.

-F  fgrep mode. Disable regular expressions and perform Boyer-Moore searches. (Whether it lives up to the 'f' in fgrep is another issue).

-f pattern-file
    Treat pattern-file as a newline-separated list of patterns to use as search criteria.

    the -f option supercedes the -e option.

-g  Highlight matches. This option causes grep to 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 the less(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 "/i" Perl regular expression switch. See perlre.

-L  List files which do no match any pattern. This option takes precedence over -l.

-l  List files containing matches. This option tells grep not to print any matches but only the names of the files containing matches. This option implies the -1 option.

-n  Number lines. Before outputting a given match, grep will first output its line corresponding to the value of the Perl magic scalar $. (whose documentation is in perlvar).

-s  Suppress diagnostic messages to the standard error.

-R and -r
    Recursively scan directories. This option causes grep to descend directories in a left-first, depth-first manner and search for matches in the files of each directory it encounters. The presence of -r implies a file argument of ., the current directory, if the user does not 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 causes grep to send diagnostic messages to the standard error when skipping symbolic links to directories, when skipping directories because the user did not give the -r switch, when skipping non-plain files (see "-f" in perlfunc), when skipping non-text files (see "-T" in perlfunc), and when opening a file for searching

-u  Underline matches. This option causes grep to 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. See perlre for 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

TODO

•   Add more cool examples. :-)

•   Perhaps allow the user to provide an exclusion pattern for skipping over files whose names match the pattern.

AUTHOR
tcgrep was written by Tom Christiansen with updates by Greg Bacon and Paul Grassie.

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.