grep -F, what is it good for?

Hello, Unix-Forums!

I have a simple question:

I cannot see any difference between

grep [expression] [file]

and

grep -F [expression] [file]

The help says that "PATTERN is a set of newline-separated fixed strings"

Isn't this default anyway?
I'm a little bit confused.

The key word is "string" as opposed to pattern. Fgrep, or grep -F doesn't do any regular expression matching. Consider searching for the string .*.* in a file:

grep -F ".*.*" filename
grep "\.\*\.\*" filename

See the difference? Using -F allows the search criteria to be free of any escape characters.

Also, if you are searching for strings, rather than patterns, I believe that using the -F option might result in quicker searches because there isn't any regular expression work involved with the scanning of each input record (I reserve the right to be wrong on that assumption).

1 Like

Ah, so using -F avoids interpreting * as a wildcard?

That means it would threat everything as a normal letter instead of using special functions like *.

Did I get it?

Yes. Create a file and try it out; it's always fun to experiment with things like this.

Also, if you do not need regular expression, a literal string match using grep -F can be quite a bit faster...