$ cat test_in.csv
id name
123 john
34 john
567 john
11 peter
899 peter
87 helen
961 Anonymous Monk
####
$ cat -vet test_in.csv
id^Iname$
123^Ijohn$
34^Ijohn$
567^Ijohn$
11^Ipeter$
899^Ipeter$
87^Ihelen$
961^IAnonymous Monk$
####
#!/usr/bin/env perl
use strict;
use warnings;
use autodie;
use constant NAME => 1;
my $infile = 'test_in.csv';
my $outfile = 'test_out.csv';
use Text::CSV;
my %seen;
{
my $csv = Text::CSV::->new({
binary => 1, sep_char => "\t", quote_char => undef,
});
open my $fh_in, '<:encoding(UTF-8)', $infile;
open my $fh_out, '>:encoding(UTF-8)', $outfile;
(undef) = scalar <$fh_in>; # skip & discard header record
while (my $row = $csv->getline($fh_in)) {
$csv->say($fh_out, $row) unless $seen{$row->[NAME]}++;
}
}
####
$ cat test_out.csv
123 john
11 peter
87 helen
961 Anonymous Monk
####
$ cat -vet test_out.csv
123^Ijohn$
11^Ipeter$
87^Ihelen$
961^IAnonymous Monk$