Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to search for lines containing either 'cat' or 'dog' in the file animals.txt using extended regex.
Bash Scripting
grep -E '[1]' animals.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' which matches any character instead of '|' for OR.
Using '*' or '?' which are quantifiers, not OR operators.
✗ Incorrect
The pipe symbol '|' in extended regex means OR, so 'cat|dog' matches lines with 'cat' or 'dog'.
2fill in blank
mediumComplete the code to find lines starting with 'Error' followed by a space and a number in log.txt using extended regex.
Bash Scripting
grep -E '^[1] [0-9]+' log.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' or '+' after 'Error' which changes the meaning.
Using '?' which makes 'Error' optional.
✗ Incorrect
The caret '^' anchors the start of the line, so '^Error ' matches lines starting with 'Error ' exactly.
3fill in blank
hardFix the error in the code to match lines containing either 'cat', 'dog', or 'bird' in pets.txt using extended regex.
Bash Scripting
grep -E 'cat[1]dog[2]bird' pets.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' which matches any character instead of OR.
Using '*' or '+' which are quantifiers, not separators.
✗ Incorrect
The '|' symbol is used to separate alternatives in extended regex, so 'cat|dog|bird' matches any of these words.
4fill in blank
hardFill both blanks to create a pattern that matches lines with a word starting with 'a' followed by one or more digits in data.txt.
Bash Scripting
grep -E '[1][0-9][2]' data.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting '+' after 'a' which means one or more 'a's, not digits.
Not using '+' after digits, so only one digit matches.
✗ Incorrect
The pattern 'a[0-9]+' matches 'a' followed by one or more digits. The '+' after [0-9] means one or more digits.
5fill in blank
hardFill all three blanks to create a pattern that matches lines containing either 'cat', 'dog', or 'bird' followed by a space and a number in pets.txt.
Bash Scripting
grep -E '[1][2][3] [0-9]+' pets.txt
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting all animals in one option without '|'.
Missing the space before the number.
✗ Incorrect
The pattern 'cat|dog|bird [0-9]+' matches any of the three words followed by a space and one or more digits.