0
0
Bash Scriptingscripting~10 mins

Anchors (^, $) in Bash Scripting - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete 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'
A*
B$
C^
D.
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.
2fill in blank
medium

Complete 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'
A$
B^
C*
D.
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.
3fill in blank
hard

Fix 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'
A$
B^
C*
D.
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.
4fill in blank
hard

Fill 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'
A^
B$
C*
D.
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.
5fill in blank
hard

Fill 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'
A^
B+
C*
D?
Attempts:
3 left
💡 Hint
Common Mistakes
Not anchoring the start with ^.
Using ? which means zero or one instead of * or +.
Misplacing the anchors.