Bird
0
0

This script is intended to replace all occurrences of 'cat' with 'dog' in a file named pets.txt. What is wrong?

medium📝 Debug Q14 of 15
Bash Scripting - Text Processing in Scripts
This script is intended to replace all occurrences of 'cat' with 'dog' in a file named pets.txt. What is wrong?
sed 's/cat/dog/g pets.txt'
Ased cannot replace text
BFile name should come before the command
CMissing closing single quote after g
DThe command should use double quotes instead of single quotes
Step-by-Step Solution
Solution:
  1. Step 1: Check sed command syntax

    The substitution command must be enclosed in quotes fully: 's/cat/dog/g'
  2. Step 2: Identify the error in the given command

    The closing single quote is missing after the g, causing a syntax error.
  3. Final Answer:

    Missing closing single quote after g -> Option C
  4. Quick Check:

    Quotes must enclose entire sed expression [OK]
Quick Trick: Check for matching quotes around sed expressions [OK]
Common Mistakes:
MISTAKES
  • Forgetting to close quotes
  • Misplacing file name inside quotes
  • Thinking sed can't replace text

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Bash Scripting Quizzes