To sort with uniq you can use
sort -u utils. So you must transform string into multiline, sort, then back to original format.
This man do string manipulation with complex
sed command which I try avoid if possible, because it force read a lot of
sed manual and debug code a long:
My solution is to use
awk. I think that it more verbose and really can be written correct from first attempt: