๐Ÿ“š General & Other

Fixed-String Matching Beats Regex for Literal Terms

treats the pattern as a regular expression. treats it as a literal string, and for literal terms the second is both safer and faster.

grep 'term' treats the pattern as a regular expression. grep -F 'term' treats it as a literal string, and for literal terms the second is both safer and faster.

Metacharacters in your search term

A term containing ., +, ?, ( or [ is a pattern, not a literal, under default grep. Searching for v1.2 also matches v1x2. Searching for c++ is a syntax error in extended mode. -F removes the entire class of problem.

Speed on large inputs

Fixed-string matching uses algorithms that skip ahead through the input rather than testing every position. On multi-gigabyte files the difference is substantial.

Multiple terms at once

grep -F -f terms.txt input.txt keeps lines matching any of the fixed strings in a file, one per line. That is the efficient way to filter a large list against a large term set โ€” far better than looping the filter once per term, which rereads the input every time.

Try it: Keep Lines Containing on SeoWolf's Notepad.