Challenge - 5 Problems
Regex Anchor 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?
data.txt with the following lines:apple application pineapple snapple apple pie
What is the output of this command?
grep '^apple$' data.txt
Bash Scripting
grep '^apple$' data.txtAttempts:
2 left
💡 Hint
The ^ anchor matches the start of the line, and $ matches the end of the line.
✗ Incorrect
The pattern '^apple$' matches lines that contain exactly 'apple' with nothing before or after. So only the line 'apple' matches.
💻 Command Output
intermediate2:00remaining
Which lines does this grep command print?
Given a file
What lines will this command print?
log.txt with these lines:error: file not found warning: low disk space error: access denied info: update complete
What lines will this command print?
grep '^error:' log.txt
Bash Scripting
grep '^error:' log.txtAttempts:
2 left
💡 Hint
The ^ anchor matches the start of the line, so only lines starting with 'error:' are matched.
✗ Incorrect
Lines starting exactly with 'error:' are matched. So the two error lines are printed.
📝 Syntax
advanced2:00remaining
Which grep pattern matches lines ending with '.txt'?
You want to find lines in a file that end exactly with '.txt'. Which grep pattern is correct?
Attempts:
2 left
💡 Hint
The $ anchor matches the end of the line. The dot must be escaped to match a literal dot.
✗ Incorrect
Pattern '\.txt$' matches lines ending with '.txt'. '^\.txt' matches lines starting with '.txt'. '\.txt' matches anywhere. '^txt$' matches lines exactly 'txt'.
🔧 Debug
advanced2:00remaining
Why does this grep command not match any lines?
You run this command:
But no lines are printed, even though the file has lines starting with 'error:'. Why?
grep '^error$' log.txt
But no lines are printed, even though the file has lines starting with 'error:'. Why?
Attempts:
2 left
💡 Hint
Check if the lines exactly match the pattern or have extra characters.
✗ Incorrect
The pattern '^error$' matches lines that are exactly 'error'. Lines like 'error:' have extra characters and do not match.
🚀 Application
expert2:00remaining
How many lines match this grep pattern?
Given a file
How many lines will this command print?
words.txt with these lines:cat concatenate scatter cater act
How many lines will this command print?
grep '^cat$' words.txt
Attempts:
2 left
💡 Hint
The pattern matches lines exactly equal to 'cat'.
✗ Incorrect
Only the line 'cat' matches exactly. Other lines contain 'cat' but have extra letters.