fgrep -- search a file for a character string


fgrep [-bci] [-h|-l] [-nvx][string] [file... ]


fgrep (fixed string grep) searches files for a character string and prints all lines that contain that string. fgrep is different from grep and egrep because it searches for a string instead of searching for a pattern that matches an expression. It uses a fast and compact algorithm.

fgrep processes supplementary code set characters according to the locale specified in the LC_CTYPE environment variable (see LANG on environ(5)), except as noted under the -i option below. Pattern searches are performed on characters, not bytes.

The characters ``$'', ``*'', ``['', ``^'', ``|'', ``('', ``)'', and ``\'' are interpreted literally by fgrep, that is, fgrep does not recognize full regular expressions as does egrep. Because these characters have special meaning to the shell, it is safest to enclose the entire string in single quotes (' . . . ').

If no files are specified, fgrep assumes standard input. Normally, each line found is copied to the standard output. The filename is printed before each line found if there is more than one input file.

Command line options are:

Precede each line by the block number on which it was found. This can be useful in locating block numbers by context (first block is 0).

Print only a count of the lines that contain the pattern.

Suppress printing of filenames when searching multiple files.

Ignore uppercase/lowercase distinction during comparisons; valid for single-byte and multibyte characters.

Print the names of files with matching lines once, separated by newlines. Does not repeat the names of files when the pattern is found more than once. If the input file is stdin, then a message such as (standard input) will be written, depending upon the message locale.

Precede each line by its line number in the file (first line is 1).

Print all lines except those that contain the pattern.

Print only lines matched entirely.

-e special_string
Search for a special_string (string begins with a -).

-f file
Take the list of strings from file.


language-specific message file (See LANG on environ(5).)


ed(1), grep(1), sed(1), sh(1)

Exit codes

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


Ideally there should be only one grep command, but there is not a single algorithm that spans a wide enough range of space-time tradeoffs. Lines are limited to BUFSIZ bytes; longer lines are truncated. BUFSIZ is defined in /usr/include/stdio.h.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004