Remove adjacent duplicated words from string
I have a string like this string:
one one tow tow three three tow one three
How can i remove duplicated words to make it like this:
one tow three tow one three
The point is that I want to write a script that remove duplicated words if they are adjacent only
I have tried:
echo "$string" | awk '{for (i=1;i<=NF;i++) if (!a[$i]++) printf("%s%s",$i,FS)}{printf("\n")}'
but it removes non-adjacent duplicated words also.
echo "one one tow tow three three tow one three" | tr " " "\ " | uniq | tr "\ " " "