0
0
Linux CLIscripting~20 mins

grep with regex (-E) in Linux CLI - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Regex Grep Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of grep -E with alternation
Given a file colors.txt with the following content:
red
blue
green
yellow
purple
orange

What is the output of this command?
grep -E 'red|blue|pink' colors.txt
A
red
blue
pink
purple
B
red
blue
C
red
blue
pink
D
blue
green
Attempts:
2 left
💡 Hint
The -E option allows using extended regex. The pattern matches lines containing 'red' or 'blue' or 'pink'.
💻 Command Output
intermediate
2:00remaining
Using grep -E with character classes and quantifiers
Consider a file words.txt containing:
cat
cot
cut
cit
cet
citizen
cute

What is the output of:
grep -E '^c[aeiou]t$' words.txt
A
citizen
cute
B
cat
cot
cut
cit
cet
citizen
cute
C
cat
cot
cut
cit
cet
D
cat
cot
cut
Attempts:
2 left
💡 Hint
The pattern matches lines starting with 'c', followed by a vowel, then 't', and nothing else.
💻 Command Output
advanced
2:00remaining
Output of grep -E with grouping and quantifiers
Given a file numbers.txt with:
123
1123
11123
111123
1111123

What is the output of:
grep -E '^1{3}23$' numbers.txt
A11123
B
11123
111123
C
123
1123
11123
D
111123
1111123
Attempts:
2 left
💡 Hint
The pattern matches lines starting with exactly three '1's followed by '23' and nothing else.
💻 Command Output
advanced
2:00remaining
grep -E with optional groups and anchors
File animals.txt contains:
cat
cats
dog
dogs
caterpillar
catalog

What is the output of:
grep -E '^cat(s)?$' animals.txt
A
cat
cats
B
cat
cats
caterpillar
catalog
C
cats
caterpillar
Dcat
Attempts:
2 left
💡 Hint
The pattern matches lines starting with 'cat' and optionally ending with 's', and nothing else.
💻 Command Output
expert
3:00remaining
Complex grep -E regex with nested groups and alternation
File log.txt contains:
error123
warning456
info789
error456
warning123
info123

What is the output of:
grep -E '^(error|warning)(123|456)$' log.txt
A
error456
warning456
info123
B
error123
warning456
info123
C
error123
warning123
info789
D
error123
error456
warning123
warning456
Attempts:
2 left
💡 Hint
The pattern matches lines starting with 'error' or 'warning' followed by '123' or '456' exactly.