Exam LFCS All QuestionsBrowse all questions from this exam
Question 75

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

    Correct Answer: E

    The tr command is used for translating or deleting characters in Unix-like systems. In this instance, we want to reduce all consecutive spaces down to a single space. The correct option to achieve this is using the -s option, which squeezes repeated occurrences of the specified character into a single occurrence. The command 'tr -s ' ' < a.txt > b.txt' reads the input from a.txt, reduces consecutive spaces to a single space, and writes the output to b.txt.

Discussion
StribOption: 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.

Strib

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.

KMAVOption: E

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.