Here are all the actual test exam dumps for IT exams. Most people prepare for the actual exams with our test dumps to pass their exams. So it's critical to choose and actual test pdf to succeed.

Exam 101-500 Topic 1 Question 78 Discussion

Actual exam question for Lpi's 101-500 exam
Question #: 78
Topic #: 1
Which of the following commands replaces each occurrence of 'bob' in the file letter with 'Bob' and writes the result to the file newletter?

Suggested Answer: D Vote an answer

Explanation
The command that replaces each occurrence of 'bob' in the file letter with 'Bob' and writes the result to the file newletter is sed 's/bob/Bob/g' letter > newletter. This command uses the following options and syntax:
* s: Specifies the substitution operation.
* /: Separates the pattern and the replacement strings.
* bob: The pattern to be searched and replaced.
* Bob: The replacement string.
* g: The global flag that indicates all occurrences of the pattern in each line should be replaced, not just the first one.
* letter: The name of the input file.
* : Redirects the output to a file.
* newletter: The name of the output file.
The output of this command will be a new file called newletter that contains the same text as letter, except that every 'bob' is replaced by 'Bob'. For example, if the file letter contains the following text:
Dear bob, I hope this letter finds you well. I am writing to inform you that your subscription to our magazine has expired. If you wish to renew it, please send us a check for $50 by the end of this month. Otherwise, we will have to cancel your subscription and remove you from our mailing list. Thank you for your cooperation and support. Sincerely, Alice The file newletter will contain the following text:
Dear Bob, I hope this letter finds you well. I am writing to inform you that your subscription to our magazine has expired. If you wish to renew it, please send us a check for $50 by the end of this month. Otherwise, we will have to cancel your subscription and remove you from our mailing list. Thank you for your cooperation and support. Sincerely, Alice The other commands are incorrect for the following reasons:
* A. sed '/bob/Bob' letter > newletter: This command is missing the s option and the second / delimiter, and will produce an error message.
* B. sed s/bob/Bob/ letter < newletter: This command is using the wrong redirection operator (< instead of
>), and will try to read the input from newletter instead of letter, and write the output to the standard output instead of newletter.
* C. sed's/bob/Bob' letter > newletter: This command is missing a space between sed and the first ', and will produce an error message.
* E. sed 's/bob, Bob/' letter > newletter: This command is using a comma (,) instead of a slash (/) as a delimiter, and will produce an error message.
References:
* [LPI Exam 101 Detailed Objectives], Topic 103: GNU and Unix Commands, Objective 103.7: Perform basic file management, Weight: 4, Key Knowledge Areas: Use of sed to edit files in place.
* How to Use the sed Command on Linux, Topic: Substituting Text.

by Elvira at May 12, 2025, 12:16 PM

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
Nick name: Submit Cancel
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.