Hi everyone,
I've used this site for a while an unregistered user. This is my first post.
I have multiple strings (eg. say two, firstLIST=(0 1 2) and secondLIST=(2 3)) and want to create a single string composed of their unique sorted elements. For the sample strings above, I'd like to build masterLIST=(0 1 2 3).
I suppose I could write the elements of firstLIST and secondLIST to files
Code:
echo ${firstLIST[@]} > firstFILE
echo ${secondLIST[@]} > secondFILE
then use
Code:
sort firstFILE secondFILE | uniq > masterFILE
as this gives me a file populated with the elements I'm after, but I'm not sure how to read the elements back into masterLIST... and it doesn't seem "right" to create files to accomplish this. Is there a way to do this by manipulating the strings ${firstLIST[@]} and ${secondLIST[@]} directly?
The closest I've come (not close at all) is
Code:
masterLIST=${firstLIST[@]}" "${secondLIST[@]}
but masterLIST built this way has only one element
Code:
$echo ${masterLIST[@]}
0 1 2 2 3
$echo ${#masterLIST[@]}
1
and I don't have access to the individual digits to then try to figure out how to remove duplicates.
Thanks for any help,
Chris