grep for text filtering. But in some situations we may need more extended tool to match given pattern in given text files. This tool is called
Extended Global Regular Expression Print or simply
egrep provides extended features over regular
egrep command is like below.
egrep FLAG REGEX FILE
FLAGis used to change some behaivour of
REGEXis the pattern we want to search in regex format.
FILEis the file name we will search in
We can use
egrep to search normal text without providing regular expression. We just need provide the term we want to search. In this example we will search
ismail in the file named
$ egrep ismail /etc/passwd
Match Lines Contains Numeric Characters
We can specify numeric characters by using
[0-9] which means one of numeric value from 0 to 9.
$ egrep '[0-9]'/etc/passwd
Match Lines Contains Alphabet Characters
We can also specify alphabet characters with
[a-z] for lowercase characters and
[A-Z] for uppercase characters. In this example we will match upper case characters.
$ egrep '[A-Z]'/etc/passwd
Match All Lines Starting with Alphabet
We can match the start of the lines with
^ sign. In this example we will look all lines where starts with alpha character.
$ egrep '^[a-Z]' myinput.py
Match All Lines Ending with Numeric
We can specify the end of line with
$ sign. Following command will list all lines those ends with a numeric character.
$ egrep '[0-9]$' myinput.py
egrep is case senstive by default. Case sensitive means upper and lower case characters will be different like
A is different than
a. We can made our match caseinsensitive if we want with
-i option as flag. Following example will match all of following words
$ egrep -i 'ismail' myinput.py