Nathan’s solution worked, thanks to all for the replies. I do feel better this was not a solution that could fit into a tweet. Theo’s is elegant, but there are spaces in the data, and John’s would have work, but I can’t use perl in the environment I’m working in. Mike awk -F, '{linecount[$3]++;tmp=dup[$3];if(length(tmp)==0){dup[$3]=$0}else{dup[$3]=dup[$3]"\n"$0}} END {for (count in linecount){if(linecount[count]>1){print dup[count]}}}' Hopefully this is not a homework problem. 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 -- Nathan Panike
participants (1)
-
Mike Peckar