Searching Through Files

Contents:
Different Versions of grep
Searching for Text with grep
Finding Text That Doesn't Match
Finding a Pattern Only When It's a Word
Extended Searching for Text with egrep
Fast grep Isn't
grepping for a List of Patterns
glimpse and agrep
New greps Are Much Faster
Search RCS Files with rcsgrep
Multiline Context grep Using sed
Make Custom grep Commands (etc.) with perl
More grep-like Programs Written in Perl
Compound Searches
Narrowing a Search Quickly
Faking Case-Insensitive Searches
Finding a Character in a Column
Fast Searches and Spelling Checks with "look"
Finding Words Inside Binary Files
Highlighting grep

Different Versions of grep

grep is one of UNIX's most useful tools. As a result, everyone seems to want their own, slightly different version that solves a different piece of the problem. (Maybe this is a problem in itself; there really should be only one grep, as the manual page says.) Three versions of grep come with every UNIX system; in addition, there are six or seven freely available versions that we'll mention here, and probably dozens of others that you can find kicking around the Net.

Here are the different versions of grep and what they offer. We'll start with the standard versions:

Now for the public domain versions:

In addition, you can simulate the action of grep with sed, awk, and perl. These utilities allow you to write such variations as a grep that searches for a pattern that can be split across several lines () and other context grep programs (, ), which show you a few lines before and after the text you find. (Normal greps just show the lines that match.)

- ML