0
0
Bash Scriptingscripting~10 mins

Extended regex (grep -E) 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 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'
Acat|dog
Bcat*dog
Ccat?dog
Dcat.dog
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' which matches any character instead of '|' for OR.
Using '*' or '?' which are quantifiers, not OR operators.
2fill in blank
medium

Complete 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'
AError*
BError
CError?
DError+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '*' or '+' after 'Error' which changes the meaning.
Using '?' which makes 'Error' optional.
3fill in blank
hard

Fix 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'
A|
B.
C*
D+
Attempts:
3 left
💡 Hint
Common Mistakes
Using '.' which matches any character instead of OR.
Using '*' or '+' which are quantifiers, not separators.
4fill in blank
hard

Fill 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'
Aa+
B+
Da
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.
5fill in blank
hard

Fill 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'
Acat
B|
Cdog|bird
Dbird
Attempts:
3 left
💡 Hint
Common Mistakes
Putting all animals in one option without '|'.
Missing the space before the number.