Chapter 13. Searching Through Files
Different Versions of grep
grep is one of Unix’s most useful tools. As a result, all users seem 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 manpage 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, as well as 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:
- Plain old grep
Great for searching with regular expressions (Section 13.2).
- Extended grep (or egrep)
Handles extended regular expressions. It is also, arguably, the fastest of the standard greps (Section 13.4).
- Fixed grep (or fgrep)
So named because it matches fixed strings. It is sometimes inaccurately called “fast grep“; often it is really the slowest of them all. It is useful to search for patterns with literal backslashes, asterisks, and so on that you’d otherwise have to escape somehow. fgrep has the interesting ability to search for multiple strings (Section 13.5).
Of course, on many modern Unixes all three are the same executable, just with slightly different behaviors, and so you may not see dramatic speed differences between them. Now for the freeware versions:
- agrep, or “approximate grep"
A tool that finds lines that “more or less” match ...