I finally came up with a solution. you can choose which field to diff, and then print a diff report based on that field
use strict; use warnings; if ($#ARGV < 1) { die "usage csvout_compare.pl <csvoutout1> <csvout2> +<csvoutout3>.....\n"}; my $f=0; my %allhash; my @indexes_to_print; my %data; my @line; my $index; foreach my $files (@ARGV) { $f++; open FILE,$files or die "Cannot open $files\n"; print "Opened $files \n"; while (<FILE>) { next if (/csvout_ID/); chomp; @line = split(/,/,$_); $index = $line[0].".".$line[1]; $allhash{$index} = 1; $data{$f}{$index} = "$_"; } close FILE; } foreach $index (keys %allhash) { my @temparray; my $flag = 0; #First lets take all those indexes which are not in all files foreach my $dataset (keys %data) { if (!(exists $data{$dataset}{$index})) { push (@indexes_to_print,$index); #delete $allhash{$index}; $flag = 1; } } next if ($flag eq 1); #Now we take those indexes where the Final result is different for (my $i=1;$i<=$f;$i++) { my @temp = split(/,/,$data{$i}{$index}); $temparray[$i] = $temp[2]; if ($i>1) { if ($temparray[$i] !~ $temparray[$i-1]) { push (@indexes_to_print,$index); } } } } #uniquify @indexes_to_print # my %seen = map { $_, 1 } @indexes_to_print; my @unique_indexes = keys %seen; foreach my $index (@unique_indexes) { print "$index"; for (my $i=1;$i<=$f;$i++) { if (exists $data{$i}{$index}) { my @temp = split(/,/,$data{$i}{$index}); #print ",$i,$temp[2]"; print ",$i"; foreach (my $j=2;$j<=10;$j++) { if (exists ($temp[$j])) { print ",$temp[$j]"; } else { print ","; } } } else { print ",$i,NA,,,,,,,,"; } } print "\n"; }

In reply to My solution by tsk1979
in thread Diff CSV files - But ignore certain fields by tsk1979

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.