nerdexam
Linux_Foundation

LFCS · Question #714

You have created a really long letter and after you are done you notice that you used the name "Bob" many times but you forgot to capitalize it in many instances. Which command would replace "bob"…

The correct answer is D. sed 's/bob/Bob/g' letter > newletter. The sed command with the s/old/new/g substitution and global flag is used to replace all occurrences of a string within a file and redirect the output to a new file.

Submitted by brentm· Apr 18, 2026Essential Commands

Question

You have created a really long letter and after you are done you notice that you used the name "Bob" many times but you forgot to capitalize it in many instances. Which command would replace "bob" with "Bob" in all instances and generate a new letter for printing?

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

How the community answered

(51 responses)
  • A
    4% (2)
  • B
    2% (1)
  • C
    8% (4)
  • D
    73% (37)
  • E
    14% (7)

Why each option

The `sed` command with the `s/old/new/g` substitution and global flag is used to replace all occurrences of a string within a file and redirect the output to a new file.

Ased '/bob/Bob' letter >newletter

The syntax `/bob/Bob` is incomplete for substitution in `sed`; it would attempt to print lines matching 'bob', not perform a replacement.

Bsed s/bob/Bob/letter < newletter

The input and output redirection are swapped (`< newletter` when `letter` should be the input), and the command syntax `sed s/bob/Bob/letter` is missing the quotes and global flag.

Csed 's/bob/Bob' letter > newletter

This command `sed 's/bob/Bob'` lacks the global (`g`) flag, so it would only replace the first occurrence of 'bob' on each line, not all instances.

Dsed 's/bob/Bob/g' letter > newletterCorrect

The `sed` command `s/bob/Bob/g` performs a substitution where `s` initiates the command, `bob` is the pattern to find, `Bob` is the replacement string, and the `g` flag ensures all occurrences on each line are replaced. The output redirection `> newletter` creates a new file with the changes.

Esed 's/bob. Bob/' letter > newletter

The substitution pattern `bob. Bob/` contains a literal dot and space, and is syntactically incorrect without the `s` command and proper delimiters.

Concept tested: sed command for global substitution

Source: https://www.gnu.org/software/sed/manual/sed.html#sed-commands-list

Topics

#sed#text manipulation#file editing#command line utilities

Community Discussion

No community discussion yet for this question.

Full LFCS Practice