I have arrays comprised of string elements like the following 2 examples. Each of the following lines is a string element of the array.
aaa bbb cc1 dd1 aaa bbb cc1 dd2 aaa bbb cc2 dd1 aaa bbb cc2 dd2 aaa bbb cc3 dd1 aaa bbb cc3 dd2
bbb rrr nnn ttt ooo eee ddd fff contr bbb sss nnn ttt ppp eee contr bbb sss nnn aaa ooo eee ddd fff contr bbb rrr nnn ttt yyy eee ddd fff contr
I want to simplify and remove "redundant" lines by merging in a single line duplicate attributes. The goal is to have the fewest lines possible, without the data values being confusing. So the results should be:
aaa bbb cc1/c2/c3 dd1 aaa bbb cc1/c2/c3 dd2
bbb rrr nnn ttt ooo/yyy eee ddd fff contr bbb sss nnn ttt ppp eee contr bbb sss nnn aaa ooo eee ddd fff contr
(the results are an array as well).
My current approach goes like this: remove the first column then compare all elements. if equal lines are found, merge them. remove second column, compare. It becomes though somewhat complicated, as not all lines have the same number of data values (separated by spaces).
I'm stuck here. Any help would be welcome.