How To Download, Install and Use GNU Grep On Windows? – POFTUT

How To Download, Install and Use GNU Grep On Windows?

grep is a very powerful and useful tool used in Linux and Unix operating systems. It is mainly used to match and print specified text in given text files in different formats. grep also have subversions like egrep which will provide extended functionality like regular expressions. In this tutorial, we will learn how to download, install and use grep and egrep for Windows operating systems.

Download GNU Grep

grep is a Unix or Linux tools provided as opensource. Hopefully, it is also provided for Windows operating systems and platform by GNU. We can download the grep setup file from the following page.

Download GNU Grep
Download GNU Grep

Or simply we can download from the following link directly. But keep in mind that when new versions have arrived following link will be absolute or old.

Install GNU Grep

We will start the installation by clicking to the gre-2.5.4-setup.exe We can see that the current version of the grep we will install is 2.5.4.

This may require some Administrative privileges. So we will provide the Admin privileges by click Yes to the dialog box.


Below the Setup Start Screen of the GNU Grep

We will accept the license agreement by clicking I accept the agreement like below.

Accept License Agreement
Accept License Agreement

We will set the destination location to install grep where the default is C:\Program Files\GnuWin32.

Grep Installation Location
Grep Installation Location

We will select the components we want to install. Full Installation will install both Binaries and Documentation otherwise we can select or deselect these components easily.

Grep Components
Grep Components

We will set the Start Menu Name for the GNU Grep like below.

LEARN MORE  How To Download and Install Wget For Windows?
Grep Start Menu Name
Grep Start Menu Name

Here are sme additional tasks like Creating Document Shortcuts in Start Menu Folder and Download Sources.

Grep Install Additional Tasks
Grep Install Additional Tasks

Now we can start the installation with the specified configuration. We will just click to the Install button like below.

Start Installation
Start Installation

As grep is a very tiny tool it will install quickly and we will see the following installation completed successfully screen.

Grep Installation Completed
Grep Installation Completed

Set Grep Path For Environment Variables

As specified configuration the grep is installed to the C:\Program Files\GnuWin32\ under to the binary \bin directory. In order call and use grep command from the MS-DOS or command line we need to add this path to the environment variables PATHvariable. We can also see the executable files named egrep, fgrep and grep in the following screen.

We set path different ways but the most practical one is using command line too setx like below.

> setx path "%path%;C:\Program Files\GnuWin32\bin"

Then we can check by opening a new command line or MS-DOS windows and run grep command like below.

We can see that grep command expects some option and file in order to work.

Print Grep Help Information

grep command in Windows is very similar to the Linux version. But we may need some helpful information about the usage and options. We can print help information with the --help option like below.

> grep --help
Print Grep Help Information
Print Grep Help Information

Grep Specified Word or Text

We can grep specified word or text just by providing the grep term and the file we want to grep. In this example grep term is ssh and the file we want to look is named config.txt. config.txt content is like below which is and ssh_config file from an Ubuntu box.

# This is the ssh client system-wide configuration file. See
# ssh_config(5) for more information. This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
# 1. command line options
# 2. user-specific file
# 3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options. For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Host *
# ForwardAgent no
# ForwardX11 no
# ForwardX11Trusted yes
# PasswordAuthentication yes
# HostbasedAuthentication no
# GSSAPIAuthentication no
# GSSAPIDelegateCredentials no
# GSSAPIKeyExchange no
# BatchMode no
# CheckHostIP yes
# AddressFamily any
# ConnectTimeout 0
# StrictHostKeyChecking ask
# IdentityFile ~/.ssh/id_rsa
# IdentityFile ~/.ssh/id_dsa
# IdentityFile ~/.ssh/id_ecdsa
# IdentityFile ~/.ssh/id_ed25519
# Port 22
# Protocol 2
# Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc
# MACs hmac-md5,hmac-sha1,[email protected]
# EscapeChar ~
# Tunnel no
# TunnelDevice any:any
# PermitLocalCommand no
# VisualHostKey no
# ProxyCommand ssh -q -W %h:%p
# RekeyLimit 1G 1h
SendEnv LANG LC_*
HashKnownHosts yes
GSSAPIAuthentication yes

We will run the following command

>grep ssh config.txt
Grep Specified Word or Text 
Grep Specified Word or Text

Leave a Comment