[Solved] compare rows and print the same values for the same rows


This piece makes it:

$ awk '{a[$1,$2]=a[$1,$2]$3} END{for (i in a) {print i, a[i]}}' file
B118791136 x
A118791136 XxXX
B23456433 XXx

Just stores the result in an array, having 1st and 2nd fields as indexes. At the end, it prints the result.

The result gives B23456433 instead of B 23456433, trying to split it… sed makes it:

$ awk '{a[$1,$2]=a[$1,$2]$3} END{for (i in a) {print i, a[i]}}' file | sed 's/\([A-Z]\)/\1 /'
B 118791136 x
A 118791136 XxXX
B 23456433 XXx

Update based on sudo_O’s comment

$ awk '{a[$1,$2]=a[$1,$2]$3} END{for (i in a) {split(i,b,SUBSEP); print b[1], b[2], a[i]}}' file
B 118791136 x
A 118791136 XxXX
B 23456433 XXx

Update based on new comment

@fedorqui is it possible to add a counter, somehow count the number of
the same rows in a column?

$ awk '{a[$1,$2]=a[$1,$2]$3} END{for (i in a) {split(i,b,SUBSEP); print b[1], b[2], a[i], length(a[i])}}' file
B 118791136 x 1
A 118791136 XxXX 4
B 23456433 XXx 3

9

solved compare rows and print the same values for the same rows