CompTIA Linux+ Powered by LPI (LX0-103) — Question 12
Which of the following commands will reduce all consecutive spaces down to a single space?
Answer options
- 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
Correct answer: E
Explanation
The correct answer is E, as the '-s' option in the tr command is specifically designed to squeeze multiple consecutive spaces into a single space. Options A, B, C, and D do not perform this function; A incorrectly attempts to replace spaces, B complements spaces with non-space characters, C deletes spaces entirely, and D replaces spaces with newline characters.