What is egrep?
3 egrep examples
Syntax and Options
Related Commands
What is egrep?
egrep is same as ‘grep -E’ or ‘grep –extended-regex’, which uses extended regular expression.
3 egrep Examples
First create the following employee.txt sample file.
100 Thomas Manager Sales $5,000 200 Jason Developer Technology $5,500 300 Sanjay Sysadmin Technology $7,000 400 Nisha Manager Marketing $9,500 500 Randy DBA Technology $6,000
1. Search for Specific Characters
The following example searches for either J, or N, or R.
$ egrep [JNR] employee.txt 200 Jason Developer Technology $5,500 400 Nisha Manager Marketing $9,500 500 Randy DBA Technology $6,000
2. Search for a Range
The following example searches the range 6-9. i.e It searches for 6, or 7, or 8, or 9.
$ egrep [6-9] employee.txt 300 Sanjay Sysadmin Technology $7,000 400 Nisha Manager Marketing $9,500 500 Randy DBA Technology $6,000
3. egrep OR Example
Pipe symbol is used for egrep OR. The following searches for either Marketing or DBA.
$ egrep 'Marketing|DBA' employee.txt 400 Nisha Manager Marketing $9,500 500 Randy DBA Technology $6,000
Note: egrep supports the extended grep characters: +, ?, |, and ( )
Syntax and Options
Syntax:
egrep [options] [regexp] [files]
The options of egrep are same as grep. Few of them are shown below.
Short Option | Long Option | Option Description |
---|---|---|
-c | –count | Suppress normal output; instead print a count of matching lines for each input file. With the -v, –invert-match option (see below), count non-matching lines. |
-L | –files-without-match | Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match. |
-l | –files-with-matches | Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match. |
-m | –max-count | Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, grep ensures that the standard input is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. |
-o | –only-matching | Print only the matched (non-empty) parts of a matching line, with each such part on a separate output line. |
Related Commands
grep
fgrep
rgrep
Comments on this entry are closed.
Thank You
Thanks ! Really helpful
good very useful..keep ur service..
Useful indeed. Thank you 🙂
Thanks a lot…
Great job. Very clear
nice code….
good job……………
Clear and consice.
Muchas gracias!
where is example to “fgrep”