101-400 Exam QuestionsBrowse all questions from this exam

101-400 Exam - Question 61


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

Show Answer
Correct Answer: D

The correct command to replace each occurrence of 'bob' in the file 'letter' with 'Bob' and write the result to the file 'newletter' is `sed 's/bob/Bob/g' letter > newletter`. The `s/bob/Bob/` part of the command tells `sed` to substitute (replace) 'bob' with 'Bob', and the `g` at the end ensures that this substitution is done globally, i.e., all occurrences in the file are replaced. The `>` symbol is used to redirect the output to the file 'newletter'.

Discussion

1 comment
Sign in to comment
DuboisNicolasDuclairOption: D
Oct 21, 2023

The command that replaces each occurrence of 'bob' in the file `letter` with 'Bob' and writes the result to the file `newletter` is: D. `sed 's/bob/Bob/g' letter > newletter` The `sed` command with the `'s/bob/Bob/g'` expression is used for global substitution, meaning it replaces all occurrences of 'bob' with 'Bob' in the file. The output is then redirected to the file `newletter`.