I have a file, that is sorted by first column.
10,W,A
20,W,E
30,I,W
40,A,E
50,P,E
60,S,A
70,A,P
80,A,I
100,A,S
110,I,S
120,A,N
130,E,N
I need to get all the first columns together until when the third column doesn't appear in the second column. If my third column value has already appeared in second column, it should be ignored.
My attempt to bring it using awk is as follows
$ awk -F"," ' { f[$2]++; if( !f[$3] ) { d[$3]=$1 } f[$3]++ } END { for(i in d) print i, d[i] } ' cg.txt
N 120
A 10
E 20
what I'm expecting is
N 120, 130
A 10
E 20, 40, 50