8.2 File Processing Commands
8.2.2 Searching for strings
Use the grep (Global Regular Expression Print) command to search a file or the output of a command for a specified text string. A string is one or more characters; it can be a character, a word, or a sentence. A string can include white space or punctuation if enclosed in quotations. The grep command searches a file for a character string and prints all lines that contain that pattern to the screen. The grep command is frequently used as a filter with other commands. For instance, you can issue the ps (process status) command and look for all occurrences of a specific process. The grep command is case-sensitive. You must match the pattern with respect to uppercase and lowercase letters, unless you use the -i option, which ignores the case. The -v option searches for all lines that do not match the string specified.

Figure shows the basic format of the grep command and Figure shows examples of how to search lines in a file or standard output.
Interactive Media Activity (Flash, 90 kB)
  Searching for strings

In this media activity, you are logged in as user2 and your current working directory is: /home/user2. Refer to the Class File Tree Structure by clicking the 'tree' button located on the Menu Bar and type the commands that would accomplish the requested objectives. 
Note: Be sure to press enter after each one. Click on step 1 to begin.