Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to match lines that start with 'Hello'.
Bash Scripting
grep '[1]Hello' file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using $ which matches the end of a line instead of the start.
Using * which matches zero or more of the previous character.
Using . which matches any single character.
✗ Incorrect
The caret (^) anchor matches the start of a line, so '^Hello' matches lines starting with 'Hello'.
2fill in blank
mediumComplete the code to match lines that end with 'world'.
Bash Scripting
grep 'world[1]' file.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using ^ which matches the start of a line instead of the end.
Using * which matches zero or more of the previous character.
Using . which matches any single character.
✗ Incorrect
The dollar sign ($) anchor matches the end of a line, so 'world$' matches lines ending with 'world'.
3fill in blank
hardFix the error in the grep pattern to match lines that start with 'Error' and end with '!'.
Bash Scripting
grep '[1]Error.*![2]' log.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using ^ at the start to anchor the pattern.
Confusing * and . with anchors.
Missing the $ at the end to anchor the line end.
✗ Incorrect
To match lines starting with 'Error' and ending with '!', the pattern should be '^Error.*!$'. Use ^ (B) for BLANK_1 and $ (A) for BLANK_2.
4fill in blank
hardFill both blanks to create a grep pattern that matches lines starting with 'Start' and ending with 'End'.
Bash Scripting
grep '[1]Start.*End[2]' data.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using * or . as anchors which are incorrect.
Forgetting to anchor the end with $.
Using anchors in the wrong positions.
✗ Incorrect
The caret (^) anchors the start of the line and the dollar sign ($) anchors the end. Together they ensure the line starts with 'Start' and ends with 'End'.
5fill in blank
hardFill all three blanks to create a grep pattern that matches lines starting with 'ID' followed by digits and ending with 'OK'.
Bash Scripting
grep -E '[1]ID[2][0-9][3]OK$' records.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Not anchoring the start with ^.
Using ? which means zero or one instead of * or +.
Misplacing the anchors.
✗ Incorrect
The caret (^) anchors the start. With -E, + quantifies the 'D' to one or more (ensuring starts with 'ID'), [0-9]* matches zero or more digits, ending with OK$.