Grep

Saturday, Sep 2, 2017 | 2 minute read | Updated at Saturday, Sep 2, 2017

@
Grep

Another linux command, I find very useful,

this is a command that helps you search for strings/text within documents. There are a whole lot of uses for it, but I will leave you to explore that yourself.

Its simplest form is:

grep <word> <in file>
=> grep "dog" animals.txt

The above looks for dog in a text file called animal.txt

There are flags/options you can set with the command to make things easier.

 -x = exclusive, exact match
 -v = everything but
 -i = I do not care about case

and many more.

You can also use [] and ^ to help make your search more refined.

grep ^a* fruits.txt

Finds fruits that have a in them

 grep ^a.p fruits.txt

Finds fruits that begin with an a and followed a random letter and then by a p.

grep ^[a-p] fruits.txt

Find all text that begin with an a through to P in fruits.txt
Go ahead and play with grep!

Lastly, grep can search through huge files very quickly, and outputs can be overwhelming, eg. log files. To make it easier, and this can be used for most linux commands,you can pipe commands through each other.

ps aux | grep 'root'| less

This simply means, I am looking for root in the output of ps aux but due to the volume outputted, I want to see them in pages, thus the use of less.

Go ahead and play with grep. Fun times ahead.

© 2025 Reveries

🌱 Powered by Hugo with theme Dream.

Me

Self Introduction

Passionate about people & technology. With a plethora of experience managing both people and technology. I am currently a Technical Officer with the Communications Division of CSIR - Institute for Scientific and Technological Information. Here, I am responsible for transforming research outputs into software, tools, equipments and communication systems as tools for national development.

I am BIG about community and have spent the better part of the last decade; growing and managing various tech communities in Ghana. Most recent being the Google Developer Group (GDG). I ASPIRE to INSPIRE.

I like to dabble in a lot of technology related things; from code to Rpi’s.