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
Best Answer
:space:
matches both horizontal and vertical white space. Use:blank:
instead to match horizontal whitespace only.