title: Remove/Extract rows based on Unique/duplicate Id from a CSV file
body: <p>Depending on how you look at it I need to remove rows based on if the Id is unique <strong>or</strong> extract rows if the Id has duplicates (keeping all duplicates).
  And I'm unsure/don't have enough knowledge of Perl to accomplish this. I've found similair topics but didn't have much succes. These are the examples I'm using <a href="https://stackoverflow.com/a/15592178/1465863">example 1</a>, <a href="https://stackoverflow.com/questions/23900461/perl-getting-unique-values-from-file-column?rq=1">example 2</a> and <a href="http://docstore.mik.ua/orelly/perl/cookbook/ch04_07.htm" rel="nofollow noreferrer">example 3</a>. In a previous problem someone showed me a solution with the List::MoreUtils module, so I could merge values with a common Id. This is not the case now, this one is removing rows if the id is unique. I know I can probably do this with the List::MoreUtils module but I want to do it without. This is my dummy data (copied example data from other question since the data doesn't matter), here you can see what I'm after. Order is not important.</p>
  
  <p><strong>Before:</strong></p>
  
  <pre><code>Cat_id;Cat_name;Id;Name;Amount;Colour;Bla
  101;Fruits;50010;Grape;500;Red;1
  101;Fruits;50020;Strawberry;500;Red;1
  201;Vegetables;60010;Carrot;500;White;1
  101;Fruits;50060;Apple;1000;Red;1
  101;Fruits;50030;Banana;1000;Green;1
  101;Fruits;50060;Apple;500;Green;1
  101;Fruits;50020;Strawberry;1000;Red;1
  201;Vegetables;60010;Carrot;100;Purple;1
  101;Fruits;50020;Strawberry;200;Red;1
  </code></pre>
  
  <p><strong>After:</strong></p>
  
  <pre><code>Cat_id;Cat_name;Id;Name;Amount;Colour;Bla
  101;Fruits;50020;Strawberry;500;Red;1
  201;Vegetables;60010;Carrot;500;White;1
  101;Fruits;50060;Apple;1000;Red;1
  101;Fruits;50060;Apple;500;Green;1
  101;Fruits;50020;Strawberry;1000;Red;1
  201;Vegetables;60010;Carrot;100;Purple;1
  101;Fruits;50020;Strawberry;200;Red;1
  </code></pre>
  
  <p>You can see that the rows of Grape and Banana with id 50010 and 50030 have been removed because there only exists one entry for both.</p>
  
  <p>This is my script, I'm struggeling with the part where I select the unique values from the hash and to output them (taking the Text::CSV_XS module in account). Can someone show me how to do this?</p>
  
  <pre><code>#!/usr/bin/perl -w
  use strict;
  use warnings;
  use Text::CSV_XS;
  
  my $inputfile = shift || die "Give input and output names!\n";
  my $outputfile = shift || die "Give output name!\n";
  
  open (my $infile, '&lt;:encoding(iso-8859-1)', $inputfile) or die "Sourcefile in use / not found :$!\n";
  open (my $outfile, '&gt;:encoding(UTF-8)', $outputfile) or die "Outputfile in use :$!\n";
  
  my $csv_in = Text::CSV_XS-&gt;new({binary =&gt; 1,sep_char =&gt; ";",auto_diag =&gt; 1,always_quote =&gt; 1,eol =&gt; $/}); 
  my $csv_out = Text::CSV_XS-&gt;new({binary =&gt; 1,sep_char =&gt; "|",auto_diag =&gt; 1,always_quote =&gt; 1,eol =&gt; $/});
  
  my $header = $csv_in-&gt;getline($infile);
  $csv_out-&gt;print($outfile, $header);
  
  my %data;
  
  while (my $elements = $csv_in-&gt;getline($infile)){
      my @columns = @{ $elements };       
      my $id = $columns[2];
      push @{ $data{$id} }, \@columns;
  }
  
  for my $id ( sort keys %data ){                 # Sort not important
      if @{ $data{$id} } &gt; 1                      # Here I have no idea anymore..
          $csv_out-&gt;print($outfile, \@columns);   #
  }
  </code></pre>