Untitled Document
egrep Command

egrep command stands for Extended grep - we have already seen this command in chapter-12 . Lets see more examples on egrep command

1. Basic example -

We have our csv file emp.csv where we have data fro employess , Now print only details for employess whose first name is "Amey and Nikhil"

 egrep "Amey | Nikhil" emp.csv 

2. Print the lines which are begining with Numbers only

Run below command and you will get the lines whicg are starting with numbers . We have used Regular Expressions and character class for this .

   egrep '^[a-zA-Z]' emp.csv

3. Print the lines which are begining with Alphabets only -

Use the same command of above example just add one negation ( ^ ) inside character class .

egrep '^[^a-zA-Z]' emp.csv

4. Print the lines where employeed id is begining with "10"

egrep '^10' emp.csv

5. Print the count of lines where employeed id is begining with "10"

Run the above example command with -c option and it will print the count of lines

egrep -c '^10' emp.csv

6. Print the lines which are starting with "M"

We will use regular expression "+" to get the result .

egrep 'M+' emp.csv

7. Print the lines which are starting with "Bh"

We will use regular expression "?" to get the result .

egrep 'Bh?' emp.csv
Untitled Document