0
0
Bash Scriptingscripting~5 mins

Extended regex (grep -E) in Bash Scripting - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the -E option do in the grep command?
The -E option tells grep to use extended regular expressions, allowing more powerful pattern matching like +, ?, | without escaping.
Click to reveal answer
beginner
Which symbol in extended regex means 'one or more' of the previous character or group?
The + symbol means 'one or more' of the previous character or group in extended regex.
Click to reveal answer
beginner
How do you search for lines containing either 'cat' or 'dog' using grep -E?
Use the pattern cat|dog with grep -E. For example: grep -E 'cat|dog' filename finds lines with 'cat' or 'dog'.
Click to reveal answer
intermediate
What is the difference between grep and grep -E?
grep uses basic regular expressions where some symbols like +, ?, | need escaping. grep -E uses extended regex where these symbols work directly.
Click to reveal answer
intermediate
Write a grep -E command to find lines with a digit repeated 3 times in a row.
Use the pattern [0-9]{3} with grep -E. Example: grep -E '[0-9]{3}' filename finds lines with three digits in a row.
Click to reveal answer
What does the pattern a+b match in grep -E?
AZero or more 'a' followed by 'b'
BThe characters 'a', '+', and 'b' literally
CExactly one 'a' followed by 'b'
DOne or more 'a' followed by 'b'
Which command uses extended regex to find lines with 'cat' or 'dog'?
Agrep 'cat|dog' filename
Bgrep -E 'cat|dog' filename
Cgrep -e 'cat|dog' filename
Dgrep -F 'cat|dog' filename
In grep -E, what does ? mean?
AExactly one of the previous character
BOne or more of the previous character
CZero or one of the previous character
DMatches a question mark literally
How do you match exactly 4 digits in a row using grep -E?
A<code>[0-9]{4}</code>
B<code>[0-9]+4</code>
C<code>[0-9]{,4}</code>
D<code>[0-9]{4,}</code>
Which of these is NOT a feature of extended regex in grep -E?
AUsing '\d' for digit shorthand
BUsing '|' for OR
CUsing '+' for one or more
DUsing '?' for zero or one
Explain how to use grep -E to search for multiple patterns with OR logic.
Think about how extended regex lets you use | without escaping.
You got /4 concepts.
    Describe the main quantifiers available in extended regex and how they change pattern matching.
    Quantifiers control how many times a character or group repeats.
    You got /6 concepts.