I have a list like this:
s1 d2
s1 d4
s3 d2
s4 d1
s1 d3
s4 d1
s5 d6
s3 d5
s1 d2
s1 d3
I need to obtain, for every element in the first column (s_) the list of element in the second column (d_) in the same order of appearance. In this case:
s1 d2 d4 d3 d2 d3
s3 d2 d5
s4 d1 d1
s5 d6
The order of the s_ is not important, the order of the d_ is.
Can you suggest a simple and fast approach to do it (because the list is large), maybe in awk?
Something like this, perhaps (for the command line):
Formatted prettier as an awk script:
What this does is store, by index of the first values, a string that contains the progressive values on the right side. So each time it finds one, it concatenates it to the end of that string. Then at the end, it prints each pair out.