Home > Text Processing & Search > fgrep

fgrep: Fixed String Search

fgrep is a command-line utility that searches for fixed strings within files. It is equivalent to grep -F and can be faster than grep for literal string searches because it avoids the overhead of regular expression parsing.

Overview

fgrep searches for fixed strings in specified files or standard input and prints the matching lines. It treats regular expression metacharacters as literal characters, making it useful for precisely searching strings that contain special characters.

Key Features

  • No regular expression support (searches for fixed strings only)
  • Functionally identical to grep -F
  • No need to escape special characters
  • Potentially faster for literal string searches

Key Options

fgrep shares most options with grep, but options related to regular expressions are not applicable.

Search Criteria

Output Format

Generated command:

Try combining the commands.

Description:

`fgrep` Executes the command.

Combine the above options to virtually execute commands with AI.

Usage Examples

Various examples of using fgrep for searching.

Basic String Search

fgrep "error message" log.txt

Search for the string 'error message' in the file log.txt.

Case-Insensitive Search

fgrep -i "warning" report.log

Search for the string 'warning' in the file report.log, ignoring case.

Invert Match

fgrep -v "success" access.log

Print lines from access.log that do not contain the string 'success'.

Recursive Search and List Files

fgrep -rl "TODO" .

List the names of files containing the string 'TODO' in the current directory and its subdirectories.

Whole Word Search

fgrep -w "fail" status.txt

Search for lines in status.txt that contain the whole word 'fail'.

Search with Line Numbers

fgrep -n "config" setup.ini

Search for the string 'config' in setup.ini and display the line numbers of matching lines.

Tips & Notes

fgrep can be more efficient than grep in certain situations.

fgrep Usage Tips

  • Performance: Since it avoids regular expression parsing overhead, fgrep (along with grep -F) is among the fastest for literal string searches.
  • Special Characters: fgrep treats regular expression metacharacters (e.g., ., *, ?, ^, $, [, ]) as literal characters, so you can search for them without escaping.
  • grep -F: fgrep is functionally identical to grep -F. On most systems, fgrep is a symbolic link to grep -F. Therefore, using either command is acceptable.

Same category commands