Difference between grep and fgrep command

LinuxOperating SystemProgramming

In any language or framework one of the most important and main feature is of searching the data. It not only denotes the performance of language but also represents in what manner the data is being stored. So specifically if we take an example of LINUX operating system there comes two of the important commands namely grep and fgrep.

Both of these commands are used to search any string or regular expression in file, directory or even in multiple folders. Both these commands executes in such a way that processor starts analysing the target folder or destination and search for the given string or data.

On the basis of execution of both of these commands following are the important differences.

Sr. No.Keygrepfgrep
1Definitiongrep or Global Regular Expression Print is the command in Linux which can search for any type of string on any file or list of files or even output of any command.On other hand Fgrep or the Fixed grep or grep -F is command in Linux which is again used in searching for the entire string instead of regular expression as it doesn’t recognize the regular expressions neither any meta-characters.
2ImplementationFor introducing the support of regular expression in search mechanism grep command is implemented in such a way that it consider regular expression and also meta-characters in the given search string and perform search along with them treating as separate than normal characters of the string.On other hand implementation of Fgrep does not support regular expression or any meta-character in its search and treat them as part of normal characters of the string.
3Data SearchingFor data searching grep uses Boyer-Moore algorithm for fast searching any string or regular expression.On other hand fgrep always uses the Aho-Corasick algorithm that worst O(m+n) complexity.
4Regular ExpressionAs mentioned above grep always interpreted as regular expressions in the given string for search.On other hand fgrep command interprets the PATTERN as a list of fixed strings separated by newlines.
5SyntaxSyntax for grep command would be in form of "grep "." myfile.txt"On other hand Syntax for fgrep command would be in form of "fgrep "." myfile.txt"
raja
Updated on 25-Feb-2020 06:05:24

Advertisements