Hey now, folks,

 

This seemed like it should be simple, but I’m at wits end. I simply want to find duplicates in the third column of a csv file, and output the duplicate line _and_ the original line that matched it. There’s a million examples out there that will output just the duplicate but not both.

 

In the data below, I’m looking for lines that match in the 3rd column…

 

Normal,Server,xldspntc02,,10.33.52.185,

Normal,Server,xldspntc02,,10.33.52.186,

Normal,Server,xldspntc04,,10.33.52.187,

Normal,Server,xldspntcs01,10.33.16.198,

Normal,Server,xldspntcs01,,10.33.16.199,

Normal,Server,xldsps01,10.33.16.162,

Normal,Server,xldsps02,10.33.16.163,

 

My desired output would be:

 

Normal,Server,xldspntc02,,10.33.52.185,

Normal,Server,xldspntc02,,10.33.52.186,

Normal,Server,xldspntcs01,10.33.16.198,

Normal,Server,xldspntcs01,,10.33.16.199,

 

$ awk -F, 'dup[$3]++' file.csv

 

I played around with the prev variable, but could not pumb it out fully, e.g { print prev }

 

Mike