Hamilton LaboratoriesHamilton C shell 2012User guideExternal utilities

grep

Oregon Coast

grep
Previous | Next

        Regular Expression Pattern Search of Text Files

Usage:  grep [-hcilnqsv-] [-f ptrnfile] [ pattern ] [ file1 file2 ...]

   grep uses special patterns called regular expressions to filter
   what it reads from stdin or from any files you specify.

   Regular expressions are written in this notation, in decreasing
   precedence:

      c        Any ordinary character matches itself.
      \c       Match the literal character c.  Certain
               characters are treated specially:

                 \a  Audible Alert (Bell)    \r  Carriage Return
                 \b  BackSpace               \t  Tab
                 \f  Form Feed               \v  Vertical Tab
                 \n  NewLine                 \\  Single BackSlash

                 \x  The next one or two characters are treated
                     as hex digits specifying the character code.

      ^        Beginning of line.
      $        End of line.
      .        Match any single character.
      [...]    Match any single character in the list.
      [^...]   Match any single character not in the list.
      \n       Match whatever literal text the n'th tagged
               \(...\) expression matched.
      r*       Match zero or more occurrences of r.
      r\{n\}   Match exactly n occurrences of r, where n is an
               unsigned decimal integer.
      r\{n,\}  Match at least n occurrences of r.
      r\{n,m\} Match at least n, but not more than m occurrences
               of r.
      r\{,m\}  Match at most m occurrences of r.
      r1r2     Match expression r1 followed by r2.
      \(r\)    Tagged regular expression.  Match the pattern
               inside the \(...\), and remember the literal
               text that matched.
   
   A regular expression pattern cannot contain Null, NewLine or
   CarriageReturn characters.

   When typing a regular expression on the command line, remember
   that $, [, ], ^, ( and ) have special meaning to Hamilton C shell.
   Put single quotes around the string to turn off that special
   meaning.  Also, even inside quotes, type ^^ to mean ^ except
   when it immediately follows [.

   Each matching line is copied to stdout.  If more than one file
   is being searched, each line is preceded by the name of file
   where the matched occurred plus a ':' character.

Options:

   -h           Help.  (This screen.)
   -c           Just print a count of the number of lines which
                match.
   -f ptrnfile  Read the patterns from a file.
   -i           Ignore character case.
   -l           Show just the names of any files containing at
                least one match.  Show each name only once, each
                on a separate line.
   -n           Show the line numbers of any matches.
   -q           Quiet:  don't show filenames where the matches
                occur.
   -s           Read the patterns from stdin.
   -v           Invert the pattern:  show all lines EXCEPT those
                that match.
   --           End of options.

Previous | Next