Hi..i have 2 sample file to compare such as fileA.txt and fileB.txt. I want to compare those files and print all any data on fileA.txt and not found on fileB.txt only.

But my code look incorrect and its was displayed both missing data. How could i solved it ?. Please help me..
#!/usr/bin/perl -w use strict; use warnings; use POSIX qw(floor ceil); use Getopt::Long; use Cwd; my ($help,$file1,$file2,$outputdir,$trace,$second,$minute); my $input = getcwd; my $output = getcwd; GetOptions ( "h" => \$help, "t" => \$trace, "1=s" => \$file1, "s" => \$second, "m" => \$minute, "2=s" => \$file2, "o=s" => \$outputdir ) or usage(); sub usage { exit; } my ($nm,$dt,$ext1,$ext2); my ($match,$tdate,$ttime,$tanum,$tbnum,$tdur,$tamount,$tremarks,$tstd, +$th,$tm,$ts,$tt); my ($cdate,$ctime,$canum,$cbnum,$cdur,$camount,$cremarks,$cstd,$ch,$cm +,$cs,$ct); if (defined($outputdir)) { my @tmp = split(/_/, $file1); @tmp = reverse(@tmp); my $match_file = "$outputdir/DATA_MATCH_$tmp[1]_$tmp[0]"; my $diff_file = "$outputdir/DATA_MISS_$tmp[1]_$tmp[0]"; open (MATCH, ">> $match_file") or die ("Can't open $match_file\n") +; open (MISS, ">> $diff_file") or die ("Can't open $diff_file\n"); } my %status = (); my ($tk,$ta); open (FILE1, "$file1") or die ("Can't open $file1\n"); while (my $data = <FILE1>) { chomp($data); $data =~ s/\"//g; ($tdate,$ttime,$tanum,$tbnum,$tdur,$tamount,$tremarks,$tstd) = (sp +lit(/\,/, $data))[0,1,2,3,4,5,6,7]; ($th,$tm,$ts) = (split(/:/, $ttime))[0,1,2]; if (defined($minute)) { #$tk = floor("$tm" / 10 + 0.5)*10; $tk = floor("$tm" / 10)*10; if ($tk eq 60) { $th++; if ($th eq 24) { $tt = sprintf ("%02s%02s00","00","00"); } else { $tt = sprintf ("%02s%02s00",$th,"00"); } } else { $tt = sprintf ("%02s%02s00",$th,$tk); } } else { #$tk = floor("$tm.$ts" + 0.5); $tk = floor("$tm.$ts"); $tt = sprintf ("%02s%02s00\n",$th,$tk); } $tanum = substr($tanum,1) if ($tanum =~ /^6/); $status{$tanum.$tt} = 1; } close(FILE1); open (FILE2, "$file2") or die ("Can't open $file2\n"); while (my $cdata = <FILE2>) { chomp($cdata); my $xx; $cdata =~ s/\"//g; ($cdate,$ctime,$canum,$cbnum,$cdur,$camount,$cremarks,$cstd) = (sp +lit(/\,/, $cdata))[0,1,2,3,4,5,6,7]; ($th,$tm,$ts) = (split(/:/, $ctime))[0,1,2]; if (defined($minute)) { #$tk = floor("$tm" / 10 + 0.5)*10; $tk = floor("$tm" / 10)*10; if ($tk eq 60) { $th++; if ($th eq 24) { $tt = sprintf ("%02s%02s00","00","00"); } else { $tt = sprintf ("%02s%02s00",$th,"00"); } } else { $tt = sprintf ("%02s%02s00",$th,$tk); } } else { #$tk = floor("$tm.$ts" + 0.5); $tk = floor("$tm.$ts"); $tt = sprintf ("%02s%02s00\n",$th,$tk); } $xx = $status{$canum.$tt}; if (defined($xx)) { print "MATCH,$file1,$file2,$cdate,$ctime,$canum,$cbnum,$cdur,$ +camount,$cremarks,$cstd\n" if (defined($trace)); print MATCH "$file1,$file2,$cdate,$ctime,$canum,$cbnum,$cdur,$ +camount,$cremarks,$cstd\n" if (defined($outputdir)); } else { print "MISS,$file1,$file2,$cdate,$ctime,$canum,$cbnum,$cdur,$c +amount,$cremarks,$cstd\n" if (defined($trace)); print MISS "$file1,$file2,$cdate,$ctime,$canum,$cbnum,$cdur,$c +amount,$cremarks,$cstd\n" if (defined($outputdir)); } } close(FILE2); close (MATCH) if (defined($outputdir)); close (MISS) if (defined($outputdir));

In reply to Findding missing record between 2 files ? by bh_perl

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.