Removing duplicates from string (not duplicate lines)

please help me in getting following:

Input Desired output
x="foo" foo
x="foo foo" foo
x="foo foo" foo
x="foo abc foo" foo abc
x="foo foo1 foo2" foo foo1 foo2

I need to remove duplicated from string..

tried looking into 'sort' yet?

Try the search option first next time:

Regards

'sort' works only when inputs are separated by lines...here they are separated by
spaces.
bash-3.00# echo "hello hello" | sort -u
hello hello

ok, so replace spaces with newLine, sort, and replace newLines with spaces?
How about that?

is that the only way? can't i do it using 'sed' or something?

as always there're more than one way to skin a cat.......
Don't think you can do with 'sed' only - you can try though.

I did try this way

bash-3.00# echo "hello hello hi" | tr ' \t' '\012' | sort -u | tr '\012' '\t'
hello hi bash-3.00#

Now i am getting extra spaces in the end and solution doesn't look too neat either.

please tell a better way to remove duplicates from string

another way:

printf "%s\n" apple apple orange pear | nawk '!($0 in w){s=(s?s OFS:"")$0;w[$0]}END{print s}' OFS='\t'