O'Reilly logo

Practical UNIX by Steve Moritsugu - DTR Business Systems

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Finding/Displaying Lines That Contain a Pattern

To find and display lines in a file that contain a name or pattern, you can use the grep command (you learn where it gets its name later). For example, assume that you have an employee file in which each line contains the name and information about one employee. To display just the lines from that file that contain the name Smith, you would enter this:

$ grep Smith employee-file
Smith, Carl - 555-6379, hired 3-7-92, dept 6
Smith, Dennis - 555-3291, hired 8-27-96, dept 2
Smithers, Jane - 619/555-1720, hired 4-4-89, dept 2
$

In this output, notice that only lines containing the word Smith are displayed. The other lines are not displayed. Also notice in the last line that Smith was found as part of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required