Galvanize Your Grip On Grep With This Great Grep Guide

Grep By Example is also available as a PDF Minibook, and a Grep playground helps you learn quickly.

These days, you can’t throw a USB stick without hitting something that’s running Linux. It might be a phone, an embedded device, or your TV. Either way, it’s running Linux, and somewhere along the line of the development of whatever your USB stick smacked into, somebody used the Global Regular Expression Print utility- better known as Grep. But what is Grep, and why do you need it? [Anton Zhiyanov] not only answers those questions but provides Grep by example: Interactive Guide to help you along.

Grep By Example is also available as a PDF Minibook, and a Grep playground helps you learn quickly.
Grep By Example is also available as a PDF Minibook, and a Grep playground helps you learn quickly.

To understand Linux, one must understand its commercial predecessor, Unix. One of the things that made Unix (and then Linux) unique was its philosophy: Write programs that work together, do one thing well, and handle text streams.  This philosophy describes a huge number of programs, and one of these programs is Grep. It’s installed everywhere there’s a *nix installed, and once one becomes familiar with it, their command-line-fu reaches an all new level.

At its core, Grep is simply a bloodhound. It’s scent? A magical incantation called Regular Expressions. Regular Expressions (aka Regex) are simply a way of describing what a stream of text should look like. So when you feed Grep a bit of Regular Expression, it Prints only the text that matches that expression. Neat, right?

The trouble is that Regex can be kind of hard, and Grep has various versions and capabilities that need to be learned. And this is where the article shines- it covers both in an excellent interactive tutorial that’ll help you become a Grep Guru in no time. And if you want to do a deeper dive, check out what it takes to make your own Regex Engine from scratch!

11 thoughts on “Galvanize Your Grip On Grep With This Great Grep Guide

  1. grep was created to fit an observed need. Users of the Unix ed(1) command very frequently issued the g/re/p command to print off all lines that contained the soecified regular expression.

    Someone xtracted that codepath and made it into its own command, because of this use case.

  2. About 25 or so years ago(maybe) someone wrote or ported grep to MSDOS, along with a half-dozen other Unix utilities, which offhand I cannot remember, as a training aid for those wishing to learn *nix. I found it to be a highly useful tool, and used it as a poor man’s primitive data base tool to make a simple address book. I simply typed up a text file of the entire address book clients info in one file, and named it rdex.txt. When I wanted to look up a customer I i simply grepped a term(name, address, or other) into the file and it would bring up the entire listing for that client. To make changes to the base, I would simply text-edit the file. Not sophisticated but it did what I needed to do, was cross-platform, and was a nice little exercise. Best if all, it was a product of my own limited imagination, though I’m sure it’s been done before and since.

Leave a Reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.