start page | rating of books | rating of authors | reviews | copyrights

UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 27.6 Fast grep Isn't Chapter 27
Searching Through Files
Next: 27.8 glimpse and agrep
 

27.7 grepping for a List of Patterns

egrep (27.5) lets you look for multiple patterns using its grouping and alternation operators (big words for parentheses and a vertical bar). But sometimes, even that isn't enough.

Both egrep and fgrep (27.6) support a -f option, which allows you to save a list of patterns (fixed strings in the case of fgrep) in a file, one pattern per line, and search for all the items in the list with a single invocation of the program. For example, in writing this book, we've used this feature to check for consistent usage for a list of terms across all articles:

% egrep -f terms *

(To be more accurate, we used rcsegrep (27.10), since the articles are all kept under RCS (20.14), but you get the idea.)

- TOR


Previous: 27.6 Fast grep Isn't UNIX Power ToolsNext: 27.8 glimpse and agrep
27.6 Fast grep Isn't Book Index27.8 glimpse and agrep

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