Bird
0
0

What will be the output of grep -E '^[0-9]{3}-[a-z]{2}' data.txt if data.txt contains:

medium📝 Command Output Q5 of 15
Linux CLI - Text Processing
What will be the output of grep -E '^[0-9]{3}-[a-z]{2}' data.txt if data.txt contains:
123-ab line1
456-cd line2
78-ef line3
1234-gh line4
A78-ef line3
B123-ab line1 456-cd line2
C1234-gh line4
DNo output
Step-by-Step Solution
Solution:
  1. Step 1: Understand the regex pattern

    Pattern ^[0-9]{3}-[a-z]{2} matches lines starting with exactly 3 digits, a dash, then 2 lowercase letters.
  2. Step 2: Check each line

    Lines 1 and 2 start with 3 digits and 2 letters after dash; line 3 has only 2 digits; line 4 has 4 digits.
  3. Final Answer:

    123-ab line1 456-cd line2 -> Option B
  4. Quick Check:

    {n} means exact count in regex [OK]
Quick Trick: Use {n} to match exact n repetitions in grep -E [OK]
Common Mistakes:
  • Matching lines with fewer or more digits
  • Ignoring case sensitivity in letters
  • Misreading {3} as optional

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes