Challenge - 5 Problems
Regex Grep Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate2:00remaining
What is the output of this grep command?
Given a file
What is the output of this command?
fruits.txt with the following lines:apple banana apricot blueberry avocado
What is the output of this command?
grep '^a' fruits.txt
Attempts:
2 left
💡 Hint
The caret (^) matches the start of a line.
✗ Incorrect
The command
grep '^a' selects lines starting with the letter 'a'. So it matches 'apple', 'apricot', and 'avocado'.💻 Command Output
intermediate2:00remaining
Which lines does this grep command select?
Given a file
What lines will this command print?
colors.txt with these lines:red blue green yellow black
What lines will this command print?
grep 'e$' colors.txt
Attempts:
2 left
💡 Hint
The dollar sign ($) matches the end of a line.
✗ Incorrect
The command
grep 'e$' selects lines ending with 'e'. 'blue' and 'green' end with 'e'.💻 Command Output
advanced2:00remaining
What is the output of this grep command with character classes?
Given a file
What lines will this command print?
words.txt containing:cat cot cut cit cet
What lines will this command print?
grep 'c[aeiou]t' words.txt
Attempts:
2 left
💡 Hint
The pattern matches 'c' followed by a vowel, then 't'.
✗ Incorrect
The pattern
c[aeiou]t matches words with 'c', followed by a vowel (a,e,i,o,u), then 't'. It matches all lines: 'cat'(a), 'cot'(o), 'cut'(u), 'cit'(i), 'cet'(e).💻 Command Output
advanced2:00remaining
What error or output does this grep command produce?
What happens when you run this command?
grep '[a-z' file.txt
Attempts:
2 left
💡 Hint
Unclosed character classes are treated literally by grep.
✗ Incorrect
Because the character class is not closed, grep treats the pattern as a literal string '[a-z'. So it prints lines containing that exact substring.
🧠 Conceptual
expert3:00remaining
How many lines does this grep command select?
Given a file
How many lines will this command print?
data.txt with these lines:123abc abc123 abc 123 ab123cd xyz
How many lines will this command print?
grep -E '^[0-9]+[a-z]+$' data.txt
Attempts:
2 left
💡 Hint
The pattern means: start with one or more digits, then one or more lowercase letters, and nothing else.
✗ Incorrect
Only the line '123abc' matches the pattern: it starts with digits and ends with letters, with no extra characters.