0
0
Linux CLIscripting~5 mins

grep with regex (-E) in Linux CLI - 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 (ERE), allowing more powerful pattern matching without needing to escape some special characters.
Click to reveal answer
beginner
How is grep -E different from basic grep?
Basic grep uses basic regular expressions (BRE) where some characters like ?, +, and {} need escaping. grep -E uses extended regex where these characters work directly.
Click to reveal answer
beginner
Example: What does grep -E 'cat|dog' file.txt do?
It searches file.txt for lines containing either 'cat' or 'dog'. The | means OR in extended regex.
Click to reveal answer
intermediate
Why use grep -E instead of egrep?
egrep is an older command equivalent to grep -E. Modern systems recommend using grep -E because egrep may be deprecated.
Click to reveal answer
beginner
How to match one or more digits using grep -E?
Use grep -E '[0-9]+'. The + means 'one or more' of the previous character or group.
Click to reveal answer
What does the command grep -E 'a+b' file.txt match?
ALines with 'a+b' literally
BLines with 'a' or 'b'
CLines with 'ab' only
DLines with one or more 'a' followed by 'b'
Which symbol means OR in grep -E regex?
A*
B|
C?
D.
What is the difference between grep and grep -E?
A<code>grep -E</code> only works on files
B<code>grep</code> is faster
C<code>grep -E</code> uses extended regex, <code>grep</code> uses basic regex
DNo difference
Which command is recommended for extended regex searching?
Agrep -E
Bgrep -P
Cgrep -B
Degrep
How to match zero or one occurrence of 'a' using grep -E?
Aa?
Ba*
Ca+
Da|
Explain how to use grep -E to search for lines containing either 'apple' or 'orange' in a file.
Think about how to combine two words with OR in regex.
You got /4 concepts.
    Describe the difference between basic and extended regular expressions in the context of grep.
    Focus on special characters and how they behave.
    You got /4 concepts.