Skip to main content
Linux AdministrationMediumSingle Choice

Linux Administration Question

Statement

Which of the following commands replaces each occurrence of 'bob' in the file letter with 'Bob' and writes the result to the file newletter?

#sed#substitute#global#redirection#newletter
A

sed '/bob/Bob' letter > newletter

B

sed s/bob/Bob/ letter < newletter

C

sed 's/bob/Bob' letter > newletter

D

sed 's/bob/Bob/g' letter > newletter

Correct
E

sed 's/bob, Bob/' letter > newletter

Resolution & Explanations

The sed (stream editor) command uses the syntax 's/find/replace/flags'. The s stands for substitute, and the g flag stands for 'global', ensuring all occurrences on each line are replaced. The > operator redirects the output to newletter instead of modifying the source file.