egrep—searches a file for a pattern using full regular expressions

egrep [ –bchilnsv ] [ –e special–expression ][ –f filename ][ strings ] [ filename ... ]

egrep (expression grep) searches files for a pattern of characters and prints all lines that contain that pattern. egrep uses full regular expressions (expressions with string values that use the full set of alphanumeric and special characters) to match the patterns.

Example A.18.
1   egrep 'Tom|John' datafile
2   egrep '^ [A-Z]+' file

EXPLANATION

  1. Display all lines in datafile containing the pattern either Tom or John.

  2. Display al lines starting with one or more uppercase letters.

Get UNIX® Shells by Example, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.