Linux fgrep command
On Unix-like operating systems, the fgrep command searches for fixed-character strings in a file or files. "Fixed-character" means the string is interpreted literally — metacharacters do not exist, and therefore regular expressions cannot be used.
This page covers the GNU/Linux version of fgrep.
Description
fgrep is useful when you need to search for strings which contain regular expression metacharacters, such as "$", "^", etc. By specifying that the search string contains fixed characters, you don't need to escape each of them with a backslash.
If your string contains newlines, each line will be considered an individual fixed-character string to be matched in the search.
Running fgrep is the same as running grep with the -F option.
Syntax
fgrep [-b] [-c] [-h] [-i] [-l] [-n] [-s] [-v] [-x] [ -e pattern_list] [-f pattern-file] [pattern] [file]
Options
-b | 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). |
-c | Print only a count of the lines that contain the pattern. |
-h | Suppress printing of files when searching multiple files. |
-i | Ignore upper/lower case distinction during comparisons. |
-l | Print the names of files with matching lines once, separated by new lines. Does not repeat the names of files when the pattern is found more than once. |
-n | Precede each line by its line number in the file (first line is 1). |
-s | Work silently, that is, display nothing except error messages. This is useful for checking the error status. |
-v | Print all lines except those that contain the pattern. |
-x | Print only lines matched entirely. |
-e pattern_list | Search for a string in pattern-list (useful when the string begins with a "-"). |
-f pattern-file | Take the list of patterns from pattern-file. |
pattern | Specify a pattern to be used during the search for input. |
file | A path name of a file to be searched for the patterns. If no file operands are specified, the standard input will be used. |
Examples
fgrep "support" myfile.txt
Search for "support" in the file myfile.txt.
Related commands
ed — A simple text editor.
egrep — Filter text which matches an extended regular expression.
grep — Filter text which matches a regular expression.
sed — A utility for filtering and transforming text.
sh — The Bourne shell command interpreter.