Name
fgrep — stdin stdout - file -- opt --help --version
Synopsis
fgrep [options
] [fixed_strings
] [files
]
The fgrep
command is just
like grep
, but instead of
accepting a regular expression, it accepts a list of fixed strings,
separated by newlines. It’s the same as grep -F
. For example, if you have a
dictionary file full of strings, one per line:
$ cat my_dictionary_file aardvark aback abandon ...
you can conveniently search for those strings in a set of input files:
$ fgrep -f my_dictionary_file inputfile1 inputfile2
Normally, you’ll use the lowercase -f
option to make fgrep
read the fixed strings from a file.
You can also read the fixed strings on the command line using
quoting, but it’s a bit trickier. To search for the strings one,
two, and three in a file, you’d type:
$ fgrep 'one Note we are typing newline characters
two
three' myfile
fgrep
is convenient when
searching for nonalphanumeric characters like * and { because they
are taken literally, not as regular expression characters.
Get Linux Pocket Guide, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.