Thursday, 11 May 2017

Use of egrep command

egrep : This command stands for extended grep.It is a combination of grep & fgrep along with some additional wild card characters.
Additional wild card characters like:

a)( | ) : It matches any one string in the given list.

Ex : $egrep "(oracle|java|unix)" output
It matches either oracle or java or unix strings.


b){m}: It matches exact occurrences of its preceding character or number.
Ex :$egrep "\<[0-9]{4}\>" num
It matches exact 4 digit number.

Ex: $egrep "\<[a-z]{4}\>" sample
It matches exact 4 digit string.

Ex: $egrep "\<ab{3}c\>" demo
It matches exact occurrence of its preceding number.

c){m,n}:It matches minimum 'm' occurrences and maximum 'n' occurrences of it's preceding character.
Ex: $egrep "\<ab{3,5}c\>" demo

Ex: $egrep "\<[0-9]{3,6}\>" num
It matches 3 or 4 or 5 or 6 digit numbers.

d){m,}: It matches minimum 'm' occurrences of its preceding character.
Ex :$egrep "\<ab{3,}c\>" demo

Ex :$egrep "\<[0-9]{3,}\>" num
It display minimum 3 digit number.

Use of fgrep command

fgrep : This command stands for faster grep.It is used to search multiple strings,but it doesn't allow to search regular expressions,it searches the strings more faster than the grep.

                                              Syntax : $frep "Strings" <filename>  

Ex:$fgrep "oracle
>unix
>java" output