I dont think we are talking about the same thing

I want this text:

a x1 x2 x3
b x4 x5
a x6 x7
b x8 x9 x10 x11
b x12

to become like this:

a x1 x2 x3 x6 x7
b x4 x5 x8 x9 x10 x11 x12

(each of a, b, c, x1, x2, etc are whole text strings)