Bash: combine arrays & delete duplicates
Hi all,
I would like to combine two arrays and delete duplicates that might occur. I tried to solve it like this: Code:
combined=( "${results1[@]}" "${results2[@]}" ) result1 (4 elements): newfoo new foo oldfoo new result2 (4 elements): new foo foo foo new new combine (6 elements only): newfoo new foo oldfoo foo foo new new In my code printf seems to have a problem with elements that have the same letters but a space inbetween. For instance "new foo", "newfoo" are the same for printf :-( Anybody can help, plz? Regards & thanks, jomann. |
Now I did the following:
Code:
# combine the two arrays to one without duplicate elements: *Or does anybody have a better idea?* Regards, jomann. |
Code:
OLDIFS="$IFS" |
Yes, that's much better!
Thanks Nominal Animal. Regards, jomann. |
Hi,
that's because you don't use printf the right way : in printf, f stands for format, and you don't give one, so Code:
result1=( newfoo 'new foo' oldfoo new ) |
Thanks again for the additional clearing of my printf-phenomenon.
Regards, jomann. |
All times are GMT -5. The time now is 03:21 PM. |