in reply to Re^2: Compare two log files line by line containing a keyword
in thread Compare two log files line by line containing a keyword

Hello rahu_6697,

Based on your updated description something like that should work:

#!/usr/bin/perl use strict; use warnings; use IO::All; use Data::Dumper; use List::Compare; my @x = io('x.log')->chomp->slurp; my @x_start = grep /mti_clk_chk/, @x && grep /start of test/, @x; my @x_period = grep /mti_clk_chk/, @x && grep /Checking the period/, @ +x; print Dumper \@x_start; # print Dumper \@x_period; my @y = io('y.log')->chomp->slurp; my @y_start = grep /mti_clk_chk/, @x && grep /start of test/, @y; my @y_period = grep /mti_clk_chk/, @x && grep /Checking the period/, @ +y; print Dumper \@y_start; # print Dumper \@y_period; my $lcStart = List::Compare->new('-u', \@x_start, \@y_start); my @LorRonlyStart = $lcStart->get_symmetric_difference; print Dumper \@LorRonlyStart; io('start.log')->appendln(@LorRonlyStart); my $lcPeriod = List::Compare->new('-u', \@x_period, \@y_period); my @LorRonlyPeriod = $lcPeriod->get_symmetric_difference; print Dumper \@LorRonlyPeriod; io('period.log')->appendln(@LorRonlyPeriod);

But I am not really sure if this is what you want as from my point of view you are comparing wrong data. I mean the lines that you provide us as sample there are not the same not just by T=<TIME> but also as syntax. For example you are comparing:

INFO @1102266 PHResourceLayer_Z4: mti_clk_chk:################ start o +f test ################ ; T=1102266 UVM_INFO @1092507 reporter Z4_COREA: mti_clk_chk: ################ sta +rt of test ################ ; T=1092507

The lines they do not have the same "@1102266" and "@1092507" so how you are going to be sure you are comparing the correct lines?

On the sample of code that I provided you above I am grepping lines with two parameters (I assume this should be enough). The problem appears when you are going to compare the arrays. Based on your description the T=<TIME> can be different but from my point of view this is not enough, you might need to add more parameters to be sure you are comparing the correct lines.

If so update your answer so we can try to help you further.

Hope this helps, BR

Seeking for Perl wisdom...on the process of learning...not there...yet!