Regular Expressions   «Prev  Next»
Lesson 7

Regular Expressions Conclusion

This module discussed regular expressions, particularly when used with grep. You learned what regular expressions are as well as some of the metacharacters that make up regular expression syntax. Using these metacharacters, you learned how to search for patterns based on their occurrence or position. Because regular expressions usually contain characters that have special meaning to the shell, regular expressions must be quoted correctly. You learned how to use single quotes, double quotes, and the backslash characters to ensure correct syntax.

Key Commands

This module introduced the following key UNIX characters:
  1. Dot (.)
  2. Asterisk (*)
  3. Brackets ([ ])
  4. Caret (^)
  5. Dollar sign ($)
  6. Double quote (")
  7. Single quote (')
  8. Backslash (\)


This module introduced you to the following terms and concepts:
  1. anchor: An anchor is a metacharacter such as ^ or $ that restricts a match to a particular position.
  2. metacharacter: A metacharacter is a character with special meaning in regular expressions and is not treated literally. Examples include the * and . metacharacters.
  3. pattern matching: Pattern matching is the task of using regular expressions to search for text.
  4. regular expression: A regular expression describes a pattern using literal characters and optional metacharacters known as regular expression syntax.
  5. shell variable: A shell variable is a place to store data that is used by the shell.
  6. string: A string is a sequence of characters.
  7. wildcards: Wildcards are characters that the shell interprets in a special way. Wildcards create patterns for matching filenames. Examples include ?, *, and [].
Function: to search the files for lines including character-string that can be a string, pattern or expression and display the result on the screen.
Common options:
  1. -c: to display only the number of matching lines;
  2. -i: to match either upper- or lowercase;
  3. -l: to display only the names of files that have matching lines;
  4. -n: to display the matched lines with their line number;
  5. -v: to display all lines that do not match pattern.
Note: Without any argument, grep takes input from the keyboard. Without redirection, the output of the grep command is sent to the screen. Forth example: Continue the first example of last section.
In the next module, you will learn to use the advanced features of the vi editor.

Regular Expression - Quiz

Click the Quiz link below to answer some questions about using grep with regular expressions.
Regular Expression - Quiz