-1

I have a file with 3 columns, separated by commas, and I want to show the duplicate lines in two columns of three columns. This is an example:

SIP/Bear-out-000b8cf123,6669544,79541868
SIP/Bear-out-000b8cf456,6619259,6549449
SIP/Bear-out-000b8cf789,6619677,6593022
SIP/Bear-out-000b8cf987,6619259,6549449
SIP/Bear-out-000b8cf654,6669544,79541868

The columns duplicates are second and thrid. The first column is always different.

The method is en BASH.

fredtantini
  • 15,966
  • 8
  • 49
  • 55
  • 2
    **I want to show the duplicate lines in two columns of three columns** Can you add some examples? – anubhava Oct 21 '14 at 09:23
  • 1
    What output do you want .. and what have you tried ? – Pratham Oct 21 '14 at 09:24
  • I tried to sort the columns with a sort command and display duplicates with a uniq command. The problem is that first column is different, and not show de duplicate lines. All lines are similar, only change the numbers in the second and third column – user3604939 Oct 21 '14 at 09:39
  • The output should be: SIP/Bear-out-000b8cf123,6669544,79541868 and SIP/Bear-out-000b8cf456,6619259,6549449 – user3604939 Oct 21 '14 at 09:43
  • Is it necessary for the first column to be in the result or are the second and third column sufficient? – Tim Zimmermann Oct 21 '14 at 09:59
  • Is necessary, This command shows me duplicates of the first column, but I can not show the second and third simultaneously: sort input | awk 'NR == 1 {p=$1; next} p == $1 { print $1 " is duplicated"} {p=$1}' FS="," – user3604939 Oct 21 '14 at 10:06

1 Answers1

0

You can use this awk command:

awk -F, '!($2 in a){a[$2]=$0; next} a[$2]{print a[$2]; delete a[$2]}' file
SIP/Bear-out-000b8cf456,6619259,6549449
SIP/Bear-out-000b8cf123,6669544,79541868
anubhava
  • 761,203
  • 64
  • 569
  • 643