O'Reilly logo

Linux Pocket Guide, 2nd Edition by Daniel J. Barrett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required