LPIC-1 Exam 101 (Linux Administrator) — Question 52
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 specifically condenses consecutive spaces into a single space. Option A is incorrect because it uses an invalid escape sequence, Option B complements but does not reduce spaces, Option C deletes all spaces instead of compressing them, and Option D replaces spaces with newlines rather than condensing them.