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:
- Dot (
.
)
- Asterisk (
*
)
- Brackets (
[ ]
)
- Caret (
^
)
- Dollar sign (
$
)
- Double quote (
"
)
- Single quote (
'
)
- Backslash (
\
)
Glossary
This module introduced you to the following terms and concepts:
- anchor: An anchor is a metacharacter such as ^ or $ that restricts a match to a particular position.
- metacharacter: A metacharacter is a character with special meaning in regular expressions and is not treated literally. Examples include the * and . metacharacters.
- pattern matching: Pattern matching is the task of using regular expressions to search for text.
- regular expression: A regular expression describes a pattern using literal characters and optional metacharacters known as regular expression syntax.
- shell variable: A shell variable is a place to store data that is used by the shell.
- string: A string is a sequence of characters.
- 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:
- -c: to display only the number of matching lines;
- -i: to match either upper- or lowercase;
- -l: to display only the names of files that have matching lines;
- -n: to display the matched lines with their line number;
- -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