Sunday, April 28, 2024
 Popular · Latest · Hot · Upcoming
11
rated 0 times [  11] [ 0]  / answers: 1 / hits: 9821  / 2 Years ago, mon, february 28, 2022, 8:43:59

I want to replace multiple spaces by a single space. I am using tr to do this. But it is also replacing new line with a space. How can I avoid it?



Code:



tr -s [:space:] ' '


Input:



He  llo
Wor ld
how are you


Required Output:



He llo
Wor ld
how are you


My Output:



He llo Wor ld how are you

More From » bash

 Answers
7

:space: matches both horizontal and vertical white space. Use :blank: instead to match horizontal whitespace only.


[#23425] Tuesday, March 1, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
laceanz

Total Points: 86
Total Questions: 113
Total Answers: 104

Location: Australia
Member since Thu, Jan 26, 2023
1 Year ago
;