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

I think I failed to explain my problem. The task is I have two log files (x.log and y.log) I have to search through them line by line and have to compare only those lines which contains a string ("mti_clk_chk") in between.

lets take an example

If my data set is like this.

LOG 1 (x.log) contains

INFO @1102266 PHResourceLayer_Z4: mti_clk_chk:################ start of test ################ ; T=1102266

INFO @1102334 PHResourceLayer_Z4: mti_clk_chk:Checking the period of MTI, MTI10 clk from SV; T=1102334


LOG 2 (y.log) contains

UVM_INFO @1092507 reporter Z4_COREA: mti_clk_chk: ################ start of test ################ ; T=1092507

UVM_INFO @1092563 reporter Z4_COREA: mti_clk_chk: Checking the period of MTI, MTI10 clk from SV; T=1092563


Then for first line I have to check "################ start of test ################ ; T=1102266" and "################ start of test ################ ; T=1092507" as value of T are not same so it should give these details in output file stating the details are not matching.

Similiarly for line 2 we have to match "Checking the period of MTI, MTI10 clk from SV; T=1102334" and "Checking the period of MTI, MTI10 clk from SV; T=1092563". Here also values of T are not matching so pass it to output file.

(For each line in the logs, every details after "mti_clk_chk:" needs to be checked )

  • Comment on Re^2: Compare two log files line by line containing a keyword

Replies are listed 'Best First'.
Re^3: Compare two log files line by line containing a keyword
by thanos1983 (Parson) on Feb 19, 2019 at 11:50 UTC

    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!
Re^3: Compare two log files line by line containing a keyword
by BillKSmith (Monsignor) on Feb 19, 2019 at 14:51 UTC
    Your second example suggests that the log files are the same except for "details". Perhaps you want to examine the first line of each file. If they contain your "keyword", report the difference between them, otherwise do nothing. Repeat for the second line of each file, then the third line of each file, etc. Even if this simplification is true, you still have not explained what kind of differences to expect or how to format them.
    Bill
Re^3: Compare two log files line by line containing a keyword
by poj (Abbot) on Feb 19, 2019 at 11:12 UTC

    Do the strings '################ start of test ################' and 'Checking the period of MTI, MTI10 clk from SV' appear only once in the files ?

    poj
      yes in both the files every line is coming just once, I need to compare those lines only