Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ fgrep(1) — Reliant UNIX 5.44c4

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ed(1)

grep(1)

egrep(1)

sed(1)

sh(1)

expressions(5)

fgrep(1)                                                           fgrep(1)

NAME
     fgrep - search for strings (fixed grep)

SYNOPSIS
     fgrep [option ...] [patternlist] [file ...]

DESCRIPTION
     fgrep reads lines from one or more files or from standard input and
     searches the lines for strings. Unless told otherwise (by options),
     fgrep copies every line containing one of the specified strings to
     standard output.

     If you specify more than one input file, the relevant file name will
     be displayed before each output line.

     The character strings for which fgrep is to search are specified
     either using patternlist or via the options -e patternlist or -f pat-
     ternfile. One of these three arguments must be specified, multiple
     specifications are not allowed.

OPTIONS
     The options -c and -l are mutually exclusive.

     No option specified
          fgrep outputs all lines that match at least one of the strings
          specified in patternlist. If you specify more than one input
          file, each output line will be preceded by the name of the file
          in which the line was found.

     -b   (block) Each output line is preceded by the number of the block
          in which it was found.

          Each file is made up of 512-byte blocks which are numbered con-
          secutively from 0.

          Option -b is sometimes useful in locating disk block numbers by
          context (see the offset argument for the od command, for exam-
          ple).

     -c   (count) fgrep outputs only the number of lines found (i.e. the
          lines that fgrep would have displayed without the -c option, see
          Example 4); the lines themselves are not displayed.

     -e list
          (expression) Synonymous with patternlist. The -e option must
          always be specified if the first expression in list begins with a
          - (dash). The -e option ensures that such strings are not inter-
          preted as an option but as a list of strings to be matched with
          the input lines.






Page 1                       Reliant UNIX 5.44                Printed 11/98

fgrep(1)                                                           fgrep(1)

     -f listfile
          (file) fgrep reads the search strings from the named listfile.
          Each line in listfile is interpreted as a string.

     -h   (hidden) When searching multiple files, fgrep does not write the
          file name before each output line.

     -i   (ignore) fgrep does not distinguish between uppercase and lower-
          case.

     -l   (list) fgrep simply outputs the names of files that contain at
          least one of the matching lines. (These are the lines that fgrep
          would output if the -l option were omitted, see Example 5.) Each
          file name is printed just once. The lines themselves are not
          displayed.

     -n   (number lines) Each output line is preceded by its line number in
          the relevant input file. Line numbering starts at 1. If fgrep is
          reading from standard input, the line number refers to the stan-
          dard input.

     -r   (recursive) Names that refer to directories are processed recur-
          sively; in other words, all the files and subdirectories in that
          directory are scanned as well.

     -v   (vice versa) fgrep outputs all lines that do not match any of the
          specified strings.

          In conjunction with option -c: fgrep prints only the number of
          lines that do not match.

          In conjunction with option -l: fgrep only outputs the names of
          files containing such lines.

     -x   (exact) fgrep outputs lines consisting solely of one of the
          specified strings.

          In conjunction with option -c: fgrep only outputs the number of
          such lines.

          In conjunction with option -l: fgrep outputs the names of files
          containing such lines.

     -y   (y - ignore) fgrep makes no distinction between uppercase and
          lowercase letters.

     --   End of the list of options. Must be specified if the first argu-
          ment begins with -.






Page 2                       Reliant UNIX 5.44                Printed 11/98

fgrep(1)                                                           fgrep(1)

     patternlist
          List of strings that fgrep is to use when comparing input lines.
          The individual strings must be separated by newline characters. A
          newline character in patternlist functions like a logical OR
          operator.

          If patternlist includes newline characters or other characters
          that have a special meaning for the shell, you must enclose pat-
          ternlist in single quotes: 'patternlist'.

     file Name of the file that fgrep is to scan. You may name any number
          of files.

          file not specified: fgrep reads input lines from the standard
          input.

   grep, fgrep, and egrep

     The grep, fgrep and egrep commands perform similar functions and are
     largely identical in terms of usage. The following section lists the
     most important differences between these commands.

     grep processes simple regular expressions if the options -E or -F are
     not specified.

     fgrep only processes character strings. fgrep can search for a large
     number of characters strings very efficiently: fgrep searches each
     individual line for all of the character strings. fgrep behaves in a
     similar way to grep -F.

     egrep processes extended regular expressions. These include simple
     regular expressions, with the following exception: The simple regular
     expressions \(regexpression\) and \{...\} have no special meaning for
     extended regular expressions and are therefore not processed by egrep.
     egrep behaves in a similar way to grep -E.

EXIT STATUS
     0   Matching lines found

     1   No matching lines found

     >1  Syntax error or "Cannot open file". This exit status remains valid
         even if lines have been found in other input files.

LOCALE
     The LCMESSAGES environment variable governs the language in which
     message texts are displayed.

     The LCCOLLATE environment variable governs the collating sequence.

     LCTYPE governs character classes and character conversion (shifting,
     option -i/-y).


Page 3                       Reliant UNIX 5.44                Printed 11/98

fgrep(1)                                                           fgrep(1)

     If LCMESSAGES, LCCOLLATE or LCCTYPE is undefined or is defined as
     the null string, it defaults to the value of LANG. If LANG is likewise
     undefined or null, the system acts as if it were not international-
     ized.

     If any of the locale variables has an invalid value, the system acts
     as if none of the variables were set.

     The LCALL environment variable governs the entire locale. LCALL
     takes precedence over all the other environment variables which affect
     internationalization.

EXAMPLES
     The files customer1 and customer2 are the basis for all the examples
     below. Their contents are as follows:

     customer1:

     080685    999.98  20 Units  Item  038   Johnson Ltd.
     120387   1240.25   3 Units  Item  023   Skinner Ltd.
     180588    330.87   1 Units  Item  332   Skinner Ltd.

     customer2:

     morrow lance, 86 sherwood street, london w1
     skinner robert, 16 garden hill, london ec3

     Example 1

     Output lines that match a string (without an option and with option
     -i):

     $ fgrep Skinner customer1 customer2
     customer1:120387   1240.25   3 Units  Item  023   Skinner Ltd.
     customer1:180588    330.87   1 Units  Item  332   Skinner Ltd.

     If you also wish to display lines containing the word skinner in
     lowercase you enter:

     $ fgrep -i skinner customer1 customer2
     customer1:120387   1240.25   3 Units  Item  023   Skinner Ltd.
     customer1:180588    330.87   1 Units  Item  332   Skinner Ltd.
     customer2:skinner robert, 16 garden hill, london ec3











Page 4                       Reliant UNIX 5.44                Printed 11/98

fgrep(1)                                                           fgrep(1)

     Example 2

     Search several strings (without an option and with the -f option):

     $ fgrep 'Skinner
     > Johnson' customer1 customer2
     customer1:080685    999.98  20 Units  Item  038   Johnson Ltd.
     customer1:120387   1240.25   3 Units  Item  023   Skinner Ltd.
     customer1:180588    330.87   1 Units  Item  332   Skinner Ltd.

     Alternatively, you could write both strings into a file called names
     (each string in a separate line) and then call fgrep as follows:

     $ fgrep -f names customer1 customer2

     Example 3

     Output lines that do not contain the given string (option -v):

     $ fgrep -v Skinner customer1 customer2
     customer1:080685    999.98  20 Units  Item  038   Johnson Ltd.
     customer2:morrow lance, 86 sherwood street, london w
     customer2:skinner robert, 16 garden hill, london ec3

     Example 4

     Display the number of lines found (option -c):

     To begin with, the number of lines containing the string Skinner are
     to be output for each input file.

     $ fgrep -c Skinner customer1 customer2
     customer1:2
     customer2:0

     Next the number of lines that do not contain the string Skinner is to
     be displayed.

     $ fgrep -c -v Skinner customer1 customer2
     customer1:1
     customer2:2

     Example 5

     Display file names only (option -l):

     First the names of files containing the string Skinner are to be out-
     put.

     $ fgrep -l Skinner customer1 customer2 customer1




Page 5                       Reliant UNIX 5.44                Printed 11/98

fgrep(1)                                                           fgrep(1)

     Now the names of files with lines not containing the string Skinner
     are to be displayed.

     $ fgrep -l -v Skinner customer1 customer2
     customer1
     customer2

     Example 6

     Display found lines with their line numbers (option -n):

     $ fgrep -n -i skinner customer1 customer2
     customer1:2:120387   1240.25   3 Units  Item  023   Skinner Ltd.
     customer1:3:180588    330.87   1 Units  Item  332   Skinner Ltd.
     customer2:2:skinner robert, 16 garden hill, london ec3

SEE ALSO
     ed(1), grep(1), egrep(1), sed(1), sh(1), expressions(5).




































Page 6                       Reliant UNIX 5.44                Printed 11/98

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026