Regular Expressions egrep for Windows: Download, Install and Examples

***If this post helped you, please support this blog by clicking one of the links on this page. Thanks :) ***

I was reading about Regular Expressions today. Many of the examples used a command-line utility called egrep. Naturally I wanted to try it. I found it difficult to download, install and get egrep working with Windows, however, as egrep was originally written for the Unix operating system. After persisting for a while, however, I was able to make it work, as follows:

  • Use the download link in Section 1.3 of this article.
  • Copy the .exe file to the folder in which you typically use the command line. For example, I usually run command line statements in the root of my C:/ directory, so I copied the .exe there.
  • Run the .exe by clicking on it.
  • Open the command prompt and verify that you in the directory where you ran the .exe
  • Type egrep
  • If egrep has installed successfully you will see a return message of:
    • Usage: egrep [OPTION] … PATTERN [FILE]… Try ‘egrep –help’ for more information’
  • egrep is now ready to be used

Using egrep

egrep can be used to search files using regular expressions. It will return the lines on which a match occurred. A simple example is a text file I created named sports.txt (saved in the C:/ directory) that contains the following:

football
soccer
baseball
tennis
track

From the command prompt I run:

egrep “ball” sports.txt

The returned result is:

football
baseball

I can also return just the lines that begin with the letter t as follows:

egrep “^t” sports.txt

The returned result is:

tennis
track

5 Responses to “Regular Expressions egrep for Windows: Download, Install and Examples”

  1. Sandy Says:

    Hi,

    You can just put the egrep.exe in your System32 folder and you are set.
    You can also add the folder you put it into to the PATH variable.

    Regards

  2. Winer Ariza Says:

    Hi!… excelent!

  3. kimk Says:

    thanks

  4. Heung Gi Says:

    thank
    i am living in the sourth korea

  5. flashguy Says:

    I’d love to read more about this

Leave a Reply