Linux egrep Command Tutorial with Examples

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-egrep-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

Linux provides 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 . egrep provides extended features over regular grep tool.

Syntax

Syntax of  egrep command is like below.

  • FLAG is used to change some behaivour of egrepcommand.
  • REGEX is the pattern we want to search in regex format.
  • FILE is the file name we will search in

Search Normally

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 /etc/passwd .

Search Normally

Search Normally

Match Lines Contains Numeric Characters

We can specify numeric characters by using [0-9] which means one of numeric value from 0 to 9.

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.

Match Lines Contains Alphabet Characters

Match Lines Contains Alphabet Characters

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.

Match All Lines Starting with Alphabet

Match All Lines Starting with Alphabet

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.

LEARN MORE  Ultimate Sed Tutorial With Examples

Match Caseinsenstive

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

  • IsmaiL
  • ismAIL
  • ISMAIL

RSS
EMAIL
FACEBOOK
FACEBOOK
GOOGLE
GOOGLE
https://www.poftut.com/linux-egrep-command-tutorial-examples/
PINTEREST
PINTEREST
INSTAGRAM

You may also like...

Leave a Reply

Your email address will not be published.

Enjoy this blog? Please spread the word :)