Join common patterns in multiple lines into one line

Hi

I have a file like

1 2
1 2 3
1 5 6
11 12
10 2
7 5
17 12

I would like to have an output as

1 2 3 5 6 10 7
11 12 17

any help would be highly appreciated
Thanks

Can you explain what is the common pattern here?

The common pattern is the occurrence of a number say '2' in multiple lines i.e with line starting with '1' and the line stating with '10'. Similarly, occurrence of number '12' in two lines stating with 11 and 17 respectively. I want to basically join the lines having common patterns into one line.

I see this is the same problem as in your previous post.
It is best solved with linked lists, where you can easily join two lists.
Old C can easily deal with pointers, but the rest (string handling etc.) is not as good as with a script interpreter.
On a script interpreter one can simulate such a list by a helper array that holds an integer that points at the following array element. The helper array goes along with the actual data array.

Thanks for the reply!
I understand that scripting somehow fails to work on such kind of lists. I used hashed arrays in perl to do the same.

Thanks :slight_smile: