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.
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.
Search in a file for a word as follows:
$ grep match_pattern filename this is the line containing match_pattern
$ grep "match_pattern" ...