Open In App

Difference between grep and fgrep command

The grep filter searches a file for a particular pattern of characters and displays all lines that contain that pattern. The fgrep filter searches for fixed-character strings in a file or files. Syntax of grep command:

grep [options] pattern [files]

Syntax of fgrep command:



fgrep [options] pattern [files]

The main difference between both commands is:

Similarity between both the commands

Consider the below file named as para2



Hi, are you using geeksforgeeks for learning computer science concepts.
Geeksforgeeks is best for learning.

Consider the below Words :

are
using
geeksforgeeks
learning
concepts

Using grep Command:

$grep -f word para

Output:

Hi, are you using geeksforgeeks for learning computer science concepts.
Geeksforgeeks is best for learning.

Using fgrep Command:

$fgrep -f word para

Output:

Hi, are you using geeksforgeeks for learning computer science concepts.
Geeksforgeeks is best for learning.

Difference between both the commands

Consider the below File :

Hi, @re you usin.g geeks*forgeeks for learni\ng computer science con/cepts.
Geeks*forgeeks is best for learni\ng.

Consider the below Words :

@re
usin.g
geeks*forgeeks
learni\ng
con/cepts

Using grep Command:

grep -f word para

Output:

Hi, @re you usin.g geeks*forgeeks for learni\ng computer science con/cepts.

Using fgrep Command:

fgrep -f word para

Output:

Hi, @re you usin.g geeks*forgeeks for learni\ng computer science con/cepts.
Geeks*forgeeks is best for learni\ng.

Article Tags :