Bird
0
0

What does the sed command sed 's/hello/world/' file.txt do?

easy📝 Conceptual Q1 of 15
Linux CLI - Text Processing
What does the sed command sed 's/hello/world/' file.txt do?
ADeletes all lines containing 'hello' from file.txt
BAppends 'world' to the end of each line in file.txt
CPrints only lines containing 'hello' from file.txt
DReplaces the first occurrence of 'hello' with 'world' in each line of file.txt
Step-by-Step Solution
Solution:
  1. Step 1: Understand the sed substitution syntax

    The command uses 's/old/new/' which means substitute the first occurrence of 'old' with 'new' in each line.
  2. Step 2: Apply to the given command

    Here, 'hello' is replaced by 'world' once per line in file.txt.
  3. Final Answer:

    Replaces the first occurrence of 'hello' with 'world' in each line of file.txt -> Option D
  4. Quick Check:

    sed substitution = Replaces first occurrence [OK]
Quick Trick: sed 's/old/new/' replaces first match per line [OK]
Common Mistakes:
  • Thinking it deletes lines instead of substitution
  • Assuming global replacement without 'g' flag
  • Confusing append with substitution

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Linux CLI Quizzes