Searching and mining "text" inside a file with grep

Searching inside a file is an important use case in text processing. We may need to search through thousands of lines in a file to find out some required data by using certain specifications. This recipe will help you learn how to locate data items of a given specification from a pool of data.

Getting ready

The grep command is the master UNIX utility for searching in the text. It accepts regular expressions and wild cards. We can produce output in various formats using the numerous interesting options that come with grep. Let's see how to do it.

How to do it...

Search in a file for a word as follows:

$ grep match_pattern filename
this is the line containing match_pattern

Or:

$ grep "match_pattern" ...

Get Linux Shell Scripting Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.