exam questions

Exam LFCS All Questions

View all questions & answers for the LFCS exam

Exam LFCS topic 1 question 76 discussion

Actual exam question from Linux Foundation's LFCS
Question #: 76
Topic #: 1
[All LFCS Questions]

Which of the following commands will reduce all consecutive spaces down to a single space?

  • A. tr '\s' ' ' < a.txt > b.txt
  • B. tr -c ' ' < a.txt > b.txt
  • C. tr -d ' ' < a.txt > b.txt
  • D. tr -r ' ' '\n' < a.txt > b.txt
  • E. tr -s ' ' < a.txt > b.txt
Show Suggested Answer Hide Answer
Suggested Answer: E 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
Strib
6 months, 4 weeks ago
Selected Answer: E
The correct option is: E. tr -s ' ' < a.txt > b.txt Explanation: The tr command is used for translating or deleting characters. In this case, we want to reduce consecutive spaces down to a single space. The -s option in the tr command is used to squeeze or collapse consecutive occurrences of a character into a single occurrence.
upvoted 1 times
Strib
6 months, 4 weeks ago
Here's an explanation of each option: A. tr '\s' ' ' < a.txt > b.txt : This command attempts to replace all whitespace characters with a single space. However, the usage of '\s' in the character set is incorrect. The '\s' is not recognized as a valid character class in tr . B. tr -c ' ' < a.txt > b.txt : This command deletes all characters except spaces. It does not reduce consecutive spaces to a single space. C. tr -d ' ' < a.txt > b.txt : This command deletes all occurrences of spaces. It does not reduce consecutive spaces to a single space. D. tr -r ' ' '\n' < a.txt > b.txt : This command replaces all spaces with newlines. It does not reduce consecutive spaces to a single space. E. tr -s ' ' < a.txt > b.txt : This is the correct command. It squeezes or collapses consecutive spaces into a single space. The resulting output will have consecutive spaces reduced to a single space.
upvoted 1 times
...
...
KMAV
9 months, 1 week ago
The correct command to reduce all consecutive spaces down to a single space is: E. tr -s ' ' < a.txt > b.txt The -s option of the tr command squeezes repeated characters and replaces them with a single character. In this case, the repeated character is a space. Therefore, the command tr -s ' ' < a.txt > b.txt will read the input file a.txt, replace all consecutive spaces with a single space, and write the output to the file b.txt.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
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.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago