I have a string with some words in them, example a=1 b=2 c=3 a=50. Now I want to parse this and create another string a=50 b=2 c=3 which is essentially the same as above except that if the same phrase before the = is encountered for the second time the first one is over written with the latest one, so in the end there are only unique phrases on the left of =. Here is what I got till now:
a="a=1 b=2 c=3 a=50"
o=()
for i in $a
do
reg=${i%=*}
if [[ ${o[*]} == *"$reg"* ]]
then
o=$(echo ${o[*]} | sed -e "s/\$reg=\S/\$i")
else
o+=( $i )
fi
done
What am I doing wrong here?
a=5, nota=50?=.sed?