"Theo" == Theo Van Dinter <felicity@kluge.net> writes:
Theo> Assuming there's no spaces in the csv, you could do: Theo> awk -F, '{print $0,$3}' | sort -k2 | uniq -D -f 1 | awk '{print $1}' Nice use of 'uniq -f 1' to re-read the file and do the de-duping. Theo> $ cat 1 Theo> Normal,Server,xldspntcs01,10.33.16.198, Theo> Normal,Server,xldspntc02,,10.33.52.185, Theo> Normal,Server,xldsps01,10.33.16.162, Theo> Normal,Server,xldspntc04,,10.33.52.187, Theo> Normal,Server,xldspntcs01,,10.33.16.199, Theo> Normal,Server,xldsps02,10.33.16.163, Theo> Normal,Server,xldspntc02,,10.33.52.186, Theo> $ cat 1 | awk -F, '{print $0,$3}' | sort -k2 | uniq -D -f 1 | awk '{print $1}' Theo> Normal,Server,xldspntc02,,10.33.52.185, Theo> Normal,Server,xldspntc02,,10.33.52.186, Theo> Normal,Server,xldspntcs01,,10.33.16.199, Theo> Normal,Server,xldspntcs01,10.33.16.198, Theo> On Mon, Mar 13, 2017 at 7:20 PM, Mike Peckar <fog@fognet.com> wrote: Theo> Hey now, folks, Theo> Theo> This seemed like it should be simple, but I’m at wits end. I simply Theo> want to find duplicates in the third column of a csv file, and output Theo> the duplicate line _and_ the original line that matched it. There’s a Theo> million examples out there that will output just the duplicate but not Theo> both. Theo> Theo> In the data below, I’m looking for lines that match in the 3^rd column… Theo> Theo> Normal,Server,xldspntc02,,10.33.52.185, Theo> Normal,Server,xldspntc02,,10.33.52.186, Theo> Normal,Server,xldspntc04,,10.33.52.187, Theo> Normal,Server,xldspntcs01,10.33.16.198, Theo> Normal,Server,xldspntcs01,,10.33.16.199, Theo> Normal,Server,xldsps01,10.33.16.162, Theo> Normal,Server,xldsps02,10.33.16.163, Theo> Theo> My desired output would be: Theo> Theo> Normal,Server,xldspntc02,,10.33.52.185, Theo> Normal,Server,xldspntc02,,10.33.52.186, Theo> Normal,Server,xldspntcs01,10.33.16.198, Theo> Normal,Server,xldspntcs01,,10.33.16.199, Theo> Theo> $ awk -F, 'dup[$3]++' file.csv Theo> Theo> I played around with the prev variable, but could not pumb it out Theo> fully, e.g { print prev } Theo> Theo> Mike Theo> _______________________________________________ Theo> Wlug mailing list Theo> Wlug@mail.wlug.org Theo> http://mail.wlug.org/mailman/listinfo/wlug Theo> _______________________________________________ Theo> Wlug mailing list Theo> Wlug@mail.wlug.org Theo> http://mail.wlug.org/mailman/listinfo/wlug