Linux_FoundationLinux_Foundation
LFCS · Question #804
LFCS Question #804: Real Exam Question with Answer & Explanation
The correct answer is D: sed 's/bob/Bob/g' letter > newletter. This question tests the use of sed for global string replacement within a file and redirecting the output to a new file.
Submitted by omar99· Apr 18, 2026Essential Commands
Question
Which of the following commands replaces each occurrence of 'bob' in the file letter with 'Bob' and writes the result to the file newletter?
Options
- Ased '/bob/Bob' letter > newletter
- Bsed s/bob/Bob/ letter < newletter
- Csed 's/bob/Bob' letter > newletter
- Dsed 's/bob/Bob/g' letter > newletter
- Esed 's/bob, Bob/' letter > newletter
Explanation
This question tests the use of sed for global string replacement within a file and redirecting the output to a new file.
Common mistakes.
- A.
sed '/bob/Bob'is an invalidsedcommand for substitution; it would attempt to match lines containing 'bob' and then interpret 'Bob' as another command. - B.
sed s/bob/Bob/is missing single quotes around thesedexpression, and< newletterwould attempt to take input fromnewletter, not write output to it. - C.
sed 's/bob/Bob'performs substitution only for the first occurrence of 'bob' on each line, not every occurrence as required. - E.
sed 's/bob, Bob/'is an incorrect substitution syntax, using a comma instead of the second/and lacking a replacement string after the second delimiter.
Concept tested. sed global string replacement and output redirection
Reference. https://man7.org/linux/man/man1/sed.1.html
Topics
#sed#Text processing#Command-line utilities#File manipulation
Community Discussion
No community discussion yet for this question.