Bird
0
0

You run grep -E '(foo|bar)+' file.txt but get an error: grep: invalid regular expression. What is the likely cause?

medium📝 Debug Q14 of 15
Linux CLI - Text Processing
You run grep -E '(foo|bar)+' file.txt but get an error: grep: invalid regular expression. What is the likely cause?
AYou forgot to quote the pattern
BThe parentheses are not escaped and your grep version does not support unescaped ()
CThe + symbol is not valid in extended regex
DThe file.txt does not exist
Step-by-Step Solution
Solution:
  1. Step 1: Check regex syntax and grep version

    Some grep versions require escaping parentheses even with -E, so unescaped () cause invalid regex error.
  2. Step 2: Verify other options

    Quoting is done, + is valid in extended regex, and file existence error would be different.
  3. Final Answer:

    The parentheses are not escaped and your grep version does not support unescaped () -> Option B
  4. Quick Check:

    Escape () if grep -E errors [OK]
Quick Trick: Escape parentheses if grep -E gives regex error [OK]
Common Mistakes:
  • Assuming + is invalid in extended regex
  • Not quoting pattern causing shell errors
  • Confusing file not found with regex error

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes