For years and years I thought the fgrep
command was a shorthand for running grep
with the -f
flag (“Obtain patterns from FILE
, one per line”). I thought this was a weird flag to promote to its own command; I never used it. Why did other people have all of these files full of regexes to search for but I’d never needed such a thing?
Life made so much more sense when I realized that fgrep
was a shortcut not for grep -f
but for grep -F
, which interprets the given pattern as a plain string instead of as a regex. Okay, now that’s an option I’ve used plenty of times.
Here’s a thought experiment: if you had an alias for grep -f
, how it would even work? The synopsis for this form of grep
looks like
grep [OPTION...] -f PATTERN_FILE [FILE...]
Presumably the heretical fgrep would work like
fgrep [OPTION...] PATTERN_FILE [FILE...]
What if you had multiple pattern files, though? How would you distinguish them from the files to be searched? Maybe you could separate them with the --
dummy argument, like
fgrep patterns1 patterns2 -- file.txt
But in that case, how would a command like
fgrep filename1 filename2
be interpreted? Is filename2
a file to read patterns from or a file to search? If all filenames up to --
are assumed to be pattern files then suddenly the user needs to type a --
every single time they want to search a file! The only sane way to specify multiple pattern files would be to require an -f
to precede each one after the first:
fgrep patterns1 -f patterns2 file.txt
This asymmetric syntax is definitely not an improvement on just typing out grep -f
.