home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 26.10 Pattern Matching Quick Reference with Examples Chapter 27 Next: 27.2 Searching for Text with grep
 

27. Searching Through Files

27.1 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:

  • Plain old grep : great for searching with regular expressions (article 27.2 ).

  • Extended grep (or egrep ): handles extended regular expressions. It is also, arguably, the fastest of the standard grep s (article 27.5 ).

  • So-called "fast grep ," or fgrep . Actually, this is the slowest of them all. Useful to search for patterns with literal backslashes, asterisks, and so on that you'd otherwise have to escape somehow. Has the interesting ability to search for multiple strings (articles 27.6 , 27.7 ).

Now for the public domain versions:

  • agrep , or "approximate grep "; a tool that finds lines that "more or less" match your search string. A very interesting and useful tool, it's part of the glimpse package. Glimpse is an indexing and query system for fast searching of huge amounts of text. Both are introduced in article 27.8 .

  • Very fast versions of grep , such as the Free Software Foundation's egrep (article 27.9 ).

  • rcsgrep , which searches through RCS files ( 20.14 ) (article 27.10 ).

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 ( 27.11 ) and other context grep programs ( 27.12 , 27.13 ) , which show you a few lines before and after the text you find. (Normal grep s just show the lines that match.)

- ML


Previous: 26.10 Pattern Matching Quick Reference with Examples UNIX Power Tools Next: 27.2 Searching for Text with grep
26.10 Pattern Matching Quick Reference with Examples Book Index 27.2 Searching for Text with grep

The UNIX CD Bookshelf Navigation The UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System