Hi,
need your help how to move the line if 2nd,& 3rd column are duplicate, compare the value on 6th column. if it's lesser than previous line(6th column), move the line into different files
Input
628801844415 510998000000015 19 22 0 NULL 0
628802944409 510998000000109 4 22 0 NULL 0
628802544405 510998000000205 4 22 0 NULL 0
628802544417 510998000000217 19 22 0 213 0
628802644413 510998000000313 19 22 0 123 0
628802644417 510998000000217 19 22 0 345 0
output File 1
628801844415 510998000000015 19 22 0 NULL 0
628802944409 510998000000109 4 22 0 NULL 0
628802544405 510998000000205 4 22 0 NULL 0
628802644413 510998000000313 19 22 0 123 0
628802644417 510998000000217 19 22 0 345 0
output file2
628802544417 510998000000217 19 22 0 213 0
#!/usr/bin/perl
use strict;
use warnings;
my $file = $ARGV[0] or die "Need to get CSV file on the command line\n
+";
my $outfile = $ARGV[1] or die "Need to get output file on the command
+line\n";
my $sum = 0;
open(my $data, '<', $file) or die "Could not open '$file' $!\n";
open (OUTFILE, "> $outfile") || die "ERROR: opening $outfile\n";
open (OUTFILE_1, "> dup_$outfile") || die "ERROR: opening $outfile\n";
while (my $line = <$data>) {
chomp $line;
my @fields = split "," , $line, -1;;
if (!$a{$fields[1],$fields[2]}++) {
$line= join( ",", @fields ) . "\n" ;
print OUTFILE ("$line");
}
else {
$line= join( ",", @fields ) . "\n" ;
print OUTFILE_1 ("$line");
}
}
close ($data);
close (OUTFILE);
close (OUTFILE_1);