glenda.party
term% ls -F
term% pwd
$home/manuals/unix_v8/1/grep
term% cat index.txt
GREP(1)                     General Commands Manual                    GREP(1)



NAME
       grep, egrep, fgrep - search a file for a pattern

SYNOPSIS
       grep [ options ] expression [ files ]

       egrep [ options ] [ expression ] [ files ]

       fgrep [ options ] [ strings ] [ files ]

DESCRIPTION
       Commands  of the grep family search the input files (standard input de‐
       fault) for lines matching a pattern.   Normally,  each  line  found  is
       copied  to  the standard output.  Grep patterns are limited regular ex‐
       pressions in the style of ed(1); it uses  a  compact  non-deterministic
       algorithm.  Egrep patterns are full regular expressions; it uses a fast
       deterministic algorithm.  Fgrep patterns are fixed strings; it is  fast
       and compact.  The following options are recognized:

       -v     All lines but those matching are printed.
       -x     (Exact)  only lines matched in their entirety are printed (fgrep
              only).
       -c     Only a count of matching lines is printed.
       -i     Ignore alphabetic case distinctions.
       -l     Only the names of files with matching lines are  listed  (once),
              separated by new-lines.
       -n     Each line is preceded by its relative line number in the file.
       -b     Each line is preceded by the block number on which it was found.
              This is sometimes useful in locating disk block numbers by  con‐
              text.
       -h     Do not print filename headers with output lines.
       -s     No output is produced, only status.
       -e expression
              Same  as  a  simple expression argument, but useful when the ex‐
              pression begins with a -.
       -f file
              The regular expression (egrep) or strings list (fgrep) is  taken
              from the file.

       Output  lines  are tagged by filename when there is more than one input
       file.  Care  should  be  taken  when  using  the  shell  metacharacters
       $*[^|()\  in  expression; it is safest to enclose the entire expression
       in single quotes ′...′.

       Fgrep searches for lines that contain one of the strings  separated  by
       new-lines.

       Egrep  accepts  regular expressions as in ed(1), except for \(, \), and
       \n, with the addition of:

       1.     A regular expression followed by + matches one  or  more  occur‐
              rences of the expression.
       2.     A regular expression followed by ?  matches 0 or 1 occurrence.
       3.     Two  regular  expressions  separated by ⎪ or newline match ocur‐
              rences of either.
       4.     Parentheses () specify grouping.

       The order of precedence of operators is [], then ∗?+,  then  concatena‐
       tion, then ⎪ and new-line.

SEE ALSO
       ed(1), sed(1), sh(1).

DIAGNOSTICS
       Exit  status is 0 if any matches are found, 1 if none, 2 for syntax er‐
       rors or inaccessible files (even if matches were found).

BUGS
       Ideally there should be only one grep, but we do not know a single  al‐
       gorithm that spans a wide enough range of space-time tradeoffs.
       Lines  are truncated at BUFSIZ characters; see setbuf(3).  Null charac‐
       ters behave as end-of-line in matches.



                                                                       GREP(1)