0
0
Bash Scriptingscripting~10 mins

Basic regex in grep 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 search for the word 'error' in the file 'log.txt'.

Bash Scripting
grep [1] log.txt
Drag options to blanks, or click blank then click option'
A-i 'error'
B'error'
C'Error'
D-v 'error'
Attempts:
3 left
💡 Hint
Common Mistakes
Using -v option which inverts the match.
Using -i which ignores case, but the task wants exact match.
2fill in blank
medium

Complete the code to search for lines starting with 'Error' in 'log.txt'.

Bash Scripting
grep [1] log.txt
Drag options to blanks, or click blank then click option'
A'Error$'
B'^error'
C'Error'
D'^Error'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'Error$' which matches lines ending with 'Error'.
Not using ^ so matches anywhere in the line.
3fill in blank
hard

Fix the error in the code to search for lines containing digits in 'data.txt'.

Bash Scripting
grep [1] data.txt
Drag options to blanks, or click blank then click option'
A'[0-9]'
B'[a-z]'
C'\\d'
D'[A-Z]'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '\d' which is not recognized by basic grep.
Using character classes that do not include digits.
4fill in blank
hard

Fill both blanks to create a grep command that finds lines with exactly three digits in a row in 'file.txt'.

Bash Scripting
grep [1][2] file.txt
Drag options to blanks, or click blank then click option'
A'[0-9]'
B'\\{3\\}'
C'[a-z]'
D'\\{2\\}'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '\{2\}' which matches two digits instead of three.
Using '[a-z]' which matches letters, not digits.
5fill in blank
hard

Fill all three blanks to create a grep command that finds lines starting with 'ID' followed by one or more digits in 'records.txt'.

Bash Scripting
grep [1][2][3] records.txt
Drag options to blanks, or click blank then click option'
A'^ID'
B'[0-9]'
C'\\+'
D'\\{1,\\}'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '\+' which is not supported in basic grep regex.
Not anchoring the pattern with '^' to match start of line.