tr
has the -s
option to squeeze repeated characters:
$ tr -s ' ' < file
aaaa bbb ccc ddd
eeee ff ggg hhh
-s, --squeeze-repeats
replace each input sequence of a repeated character that is listed in SET1 with a single occurrence of that character
Another example:
$ echo "aaa ----- bbbb ------------- ccc" | tr -s '-'
aaa - bbbb - ccc