Difference between grep and egrep
BY fazeela.ma
6 years ago

Grep is an amazing utility on command line. Every one might have heard of grep. It's a great tool to search for a pattern with in a directory or in a file. On searching for a pattern using grep, the default result will print the pattern along with the line number at which the pattern is found. Grep is one of those handy commands on bash that are often used.

Pre requisites for grep

Grep comes installed with an ubuntu machine, if it is not installed, it could be done using,

sudo apt-get grep install;

grep and egrep

I have played around with grep for a while, at some point I have noticed egrep. grep and egrep does the same function, but the way they interpret the pattern is the only difference.

Grep stands for "Global Regular Expressions Print", were as Egrep for "Extended Global Regular Expressions Print". The pattern often treated as a regular expression, for which e in egrep stands for "Extended Regular Expressions" abbreviated 'ERE' is enabled in egrep.

grep -E is same as egrep

In egrep, +, ?, |, (, and ), treated as meta characters. Where as in grep, they are rather treated as pattern instead of meta characters. By including 'backslash' followed by meta character can let the grep to treat it as meta characters like \?, \+, \{, \|, \(, and \).

ls | grep '.txt|.php'

Let us consider this example, in this we are listing all the files in the present working directory. Using pipe we are passing the output of ls to grep. The grep command will check whether there is any file with .text|.php extension.

ls | egrep '.txt|.php'

Now consider the same example with egrep, here egrep will check for files with either .txt or .php extension. By using egrep we can even search for multiple pattern, files at a time using one command. We can make grep also do the same by escaping the characters.



on 04th April 2007 / by webmaster
Linux is the epitome of the FLOSS model. Technical Solution Linux installation Dewey J. Corl (not verified) access_time 20 Sep 2021 - 17:57 Linux is not ready for the general public! (I am a Ubuntu user). For proof, 1. try to simply print labels on a Dymo label printer. It takes a LOT of work to get to the ease of label printing already available in Windows and Mac. 2. try syncing a modern Palm based PDA. Yes, jpilot and others will sync the main data, but pictures and midi files do not get transferred without a lot of extra setup. These are examples of applications that are not ready for the general public. Since an operating system only supports applications, Linux is not ready to be a common desktop for the general public. While we are waiting for the applications to catch up, keep up the good work!! Anoop John (not verified) access_time 20 Sep 2021 - 17:57 Dewey Yes you may be right. But these are not applications that a common man would use. A common man would use one of these applications - Internet browser, Chat Client, Email Client, Document Writer, Presentation Creator, Spreadsheet Editor, Movie Viewer, Music Player, CD/DVD Writer. Both examples you cited are more specific applications that only a small percentage of the whole population uses. It will take time before those hardware vendors identify the need from their perspective to address the Linux community. Krishnadas (not verified) access_time 20 Sep 2021 - 17:57 Dear Mr Anoop, Thank you very much for the free installation of LINUX done in my PC. I am getting immersed in the LINUX and seeing the versatility. To my surprise, I am able to read one of my old backup CD(wherein lot of my valuable file exist) done in DIRECT CD wizard (a custom cd writing software of Easy Cd creator in WIN98) which could not be read in XP. Installation of old version of easycd creator/direct cd program was not possible in XP. I thought that possible i lost all data. Very pleasant start! Srikanth N. S. (not verified) access_time 20 Sep 2021 - 17:57 Hi Anoop, My friend is thrilled with Ubuntu. One of his grouses with windows was that after OS installation, everything else is to be installed separately which is a real headache. WHereas if u install Linux, everything is installed as a package and he is thrilled to bits! Let linux installation spread in Trivandrum and your service in this direction is highly appreciated. Kepp up the good work Regards. PDA Freak (not verified) access_time 20 Sep 2021 - 17:57 Is it possible to install linux on a packardbell notebook ? webmaster access_time 20 Sep 2021 - 17:57 In reply to Is it possible to install by PDA Freak (not verified) Sir, It should be possible. Try installing and if it shows any issues please inform us. May be we could help you. Thank You Team Zyxware