I am novice in database

Dear Sir, I am searching for some software that convert my Big CSV data file :
1 A C Z F G
2 G Q R C
3 Z G Q
4 C F
5 O P
I have a table with 1-1000000 records like these 5 records you see, records 1 and 2 are common in G and C data
I want to sync records if they have at least two common data like 1 & 2 and generate a list like this:
1 A C Z F G Q R
2 G Q R C A Z F
3 Z G Q A C F R
4 C F A Z G Q R
5 O P

at the end we have 4 same records if we sort data and one without sync:

1 A C F G Q R Z
2 A C F G Q R Z
3 A C F G Q R Z
4 A C F G Q R Z
5 O P

Does your Software can help me? How?
Thank you

Can you please elaborate the logic – how did you go from

1 A C Z F G
2 G Q R C

to

1 A C Z F G Q R
2 G Q R C A Z F

?

1 has A C Z F G
2 has G Q R C
1 & 2 have two words in common thus they sync to one Data A C Z F G Q R
other lines too will recognize and syncronize if they have two common fields

This is a clustering task. While it’s technically feasible to do in EasyMorph using complex logic, for a dataset with 1mln records it would take probably weeks to complete as it would require at least 10^12 matches.

It should be solved by writing a program (e.g. in F# or Python) using clustering algorithms, not a general-purpose tool like EasyMorph.