Recall & Review
beginner
What does the command
grep 'pattern' filename do?It searches the file named
filename for lines that match the given pattern and prints those lines.Click to reveal answer
beginner
What is a regular expression (regex) in the context of
grep?A regex is a special text pattern that describes a set of strings.
grep uses regex to find matching text in files.Click to reveal answer
beginner
How do you use
grep to search for lines that start with the word 'Hello'?Use the caret symbol
^ to match the start of a line: grep '^Hello' filename.Click to reveal answer
beginner
What does the dot
. mean in a regex pattern?The dot
. matches any single character except a newline.Click to reveal answer
intermediate
How can you search for lines containing either 'cat' or 'dog' using
grep?Use the alternation symbol
\| inside quotes: grep 'cat\|dog' filename.Click to reveal answer
Which symbol in regex matches the start of a line?
✗ Incorrect
The caret symbol ^ matches the start of a line in regex.
What does the regex pattern
grep 'a.b' filename match?✗ Incorrect
The dot '.' matches any single character, so 'a.b' matches 'a' + any character + 'b'.
How do you tell grep to treat the pattern as a basic regex?
✗ Incorrect
The
-G option tells grep to use basic regular expressions (default behavior).Which grep option allows using extended regex with alternation
| without escaping?✗ Incorrect
The
-E option enables extended regex, allowing alternation with | without escaping.What does the regex symbol
$ match?✗ Incorrect
The dollar sign $ matches the end of a line in regex.
Explain how to use grep with a basic regex to find lines starting with a specific word.
Think about how to anchor your search to the line start.
You got /3 concepts.
Describe the difference between basic and extended regex in grep and when to use each.
Consider how you write alternation patterns.
You got /3 concepts.