GREP vs. EGREP vs. FGREP
Explore the differences between grep, egrep, and fgrep commands in Bash. Understand their syntax, options, and when to use each for effective text searching and pattern matching in files and directories.
We'll cover the following...
We'll cover the following...
- grep
- egrep
- Definition:
- Syntax:
- Options:
- Examples:
- Regex Examples
- - Finding lines with specific number of vowels:
- - Finding lines with specific characters in them and those characters don’t come at the end of line:
- - Finding each line with some sequences of characters:
- - Finding number of lines with some particular character at the end:
- - Finding lines beginning with some specific characters:
- fgrep
grep
Definition:
The command grep stands for “global regular expression print”, and is used to search for specified text patterns in files or program outputs.
Syntax:
grep [option(s)] pattern [file(s)]
Options:
| Option | Description |
|---|---|
| -E (extended regexp) | Causes grep to behave like egrep. |
| -F (fixed strings) | Causes grep to behave like fgrep. |
| -G (basic regexp) | Causes grep, egrep, or fgrep to behave like the standard grep utility. |
| -r | To search recursively through an entire directory tree (i.e., a directory and all levels |