I have been trying to do this myself based on other examples but have failed. I want awk to reprint a tab delimited file but add an extra column at the end which starts at 1 and increases as long as column1 is the same, when column1 has a new value, last column gets reset to 1....
Brief example, input if columns 1-3 and output has last column:
A11R Q9Y5X3 SNX5 1
A12L Q9Y316 MEMO1 1
A12L Q70CQ2 USP34 2
A12L Q8N7H5 PAF1 3
A12L Q8IZL8 PELP1 4
A13L Q5SY16 NOL9 1
A13L Q6P1J9 CDC73 2
A13L Q8WVC0 LEO1 3
A13L Q9Y4W2 LAS1L 4
A13L Q6PD62 CTR9 5
I know I first need to read the file and make an array of column 1 values and then print the file based on an if condition where if column1 is the same as previous row, i++
I tried:
awk '{A[++c] = $1} END {d=1; for ( i = 1; NR == i; i++ ) {if (A[i] = A[i-1]) {d++} else {d=1}; print d, $0}}'
But clearly I am missing some basics of how this works.