With suitable examples differentiate between grep and fgrep command.
grep command
|
fgrep command
|
grep is an acronym that stands for "Global Regular Expressions Print".
|
fgrep is an acronym that stands for "Fixed-string Global Regular Expressions Print".
|
grep is a program which scans a specified file or files line by line, returning lines that contain a pattern. A pattern is an expression that specifies a set of strings by interpreting characters as metacharacters.
|
fgrep (which is the same as grep - F) is fixed or fast grep and behaves as grep but does NOT recognize any regular expression meta-characters as being special. The search will complete faster because it only processes a simple string rather than a complex pattern.
|
For example the asterisk meta character (*) is interpreted as meaning "zero or more of the preceding element". This enables users to type a short series of characters and meta characters into a grep command to have the computer show us what lines in which files match.
|
For example, if I wanted to search my .bash_profile for a literal dot (.) then using grep would be difficult because I would have to escape the dot because dot is a meta character that means 'wild-card, any single character':
|
Syntax: grep [OPTIONS] PATTERN [FILE….]
|
Syntax: fgrep [-b] [-c] [-h] [-i] [-1] [-n] [- s] [-v] [-x] [ -e pattern_list] [ -f pattern-file] [pattern] [file]
|
Example:
|
Example:
fgrep “support” myfile.txt Search for “support” in the myfile.txt |