Bird
0
0

What is the output of echo 'apple apple apple' | sed 's/apple/orange/2'?

medium📝 Command Output Q4 of 15
Linux CLI - Text Processing
What is the output of echo 'apple apple apple' | sed 's/apple/orange/2'?
Aorange apple apple
Borange orange orange
Capple apple orange
Dapple orange apple
Step-by-Step Solution
Solution:
  1. Step 1: Understand the command input and substitution

    The input string has three 'apple's. The command replaces the second occurrence only.
  2. Step 2: Apply substitution to the second 'apple'

    The second 'apple' becomes 'orange', so output is 'apple orange apple'.
  3. Final Answer:

    apple orange apple -> Option D
  4. Quick Check:

    Second occurrence replaced = D [OK]
Quick Trick: Number after s/// targets specific occurrence [OK]
Common Mistakes:
  • Replacing first instead of second occurrence
  • Replacing all occurrences without 'g'
  • Miscounting occurrences

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes