Assuming there's no spaces in the csv, you could do: awk -F, '{print $0,$3}' | sort -k2 | uniq -D -f 1 | awk '{print $1}' eg: $ cat 1 Normal,Server,xldspntcs01,10.33.16.198, Normal,Server,xldspntc02,,10.33.52.185, Normal,Server,xldsps01,10.33.16.162, Normal,Server,xldspntc04,,10.33.52.187, Normal,Server,xldspntcs01,,10.33.16.199, Normal,Server,xldsps02,10.33.16.163, Normal,Server,xldspntc02,,10.33.52.186, $ cat 1 | awk -F, '{print $0,$3}' | sort -k2 | uniq -D -f 1 | awk '{print $1}' Normal,Server,xldspntc02,,10.33.52.185, Normal,Server,xldspntc02,,10.33.52.186, Normal,Server,xldspntcs01,,10.33.16.199, Normal,Server,xldspntcs01,10.33.16.198, On Mon, Mar 13, 2017 at 7:20 PM, Mike Peckar <fog@fognet.com> wrote:
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
_______________________________________________ Wlug mailing list Wlug@mail.wlug.org http://mail.wlug.org/mailman/listinfo/wlug
participants (1)
-
Theo Van Dinter