Bird
0
0

Given a file data.txt with these lines:

medium📝 Command Output Q13 of 15
Linux CLI - Text Processing
Given a file data.txt with these lines:
apple
banana
applepie
pineapple
banana split

What is the output of grep -E '^apple$|banana$' data.txt?
Aapplepie banana
Bapple banana split
Capple banana
Dapple banana banana split
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the regex pattern

    The pattern ^apple$|banana$ means lines exactly matching "apple" OR lines ending with "banana".
  2. Step 2: Match lines in the file

    "apple" matches ^apple$. "banana" matches banana$. "applepie" does not match ^apple$ due to extra characters after "apple". "pineapple" matches neither. "banana split" does not end with "banana".
  3. Final Answer:

    apple banana -> Option C
  4. Quick Check:

    ^apple$ or banana$ matches apple and banana [OK]
Quick Trick: Remember ^ means start, $ means end in regex [OK]
Common Mistakes:
  • Assuming banana split matches banana$
  • Matching applepie because it contains apple
  • Ignoring anchors ^ and $

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes