我必须逐行比较两个不同的日志文件(在每个行中检查两个符号(<form action="<?php echo $row["articleLink"] ?>">
<input type="hidden" value="clicked button 1" name="button">
<button class="newsbutton"> Lees verder.. </button>
</form>
和:
)之间的数据)并打印日志1的所有非在日志2中。我使用了这种方法,但结果不正确。
log1中的内容:
;
日志2中的内容:
INFO @0 digrf_0_drv: Constructing a digrf Driver: digrf_0_drv; T=0
INFO @648647 mti_disable_fuse_cov_inst: run_stimulus called; T=648647
INFO @1549325 mti_disable_fuse_cov_inst: CHECKING MTI DISABLE FUSE CONNECTED TO flash_mti_en; T=1549325
INFO @1549325 mti_disable_fuse_cov_inst: MTI_DISABLE fuse is correctly asserted ; T=1549325
预期输出:
UVM_INFO @1381068 mti_disable_fuse_cov [mti_disable_fuse_cov:INFO]: CHECKING MTI DISABLE FUSE CONNECTED TO flash_mti_en; T=1381068
UVM_INFO @1381068 mti_disable_fuse_cov [mti_disable_fuse_cov:INFO]: MTI_DISABLE fuse is correctly asserted ; T=1381068
UVM_INFO @1381068 reporter [Z7_COREB]: V FLAG_CLEAR: Clearing flag 1; T=1381068
UVM_INFO @1381068 reporter [Z4_COREA]: V FLAG_SET: Setting flag 2; T=1381068
现在我当前的代码是:
Constructing a digrf Driver: digrf_0_drv
run_stimulus called
编辑
如果两行或多行在日志1中具有相同的信息集,则在输出中仅打印一行。
日志1
#!/usr/bin/perl
use strict;
use warnings;
#use 5.012;
my $filename1 = 'log2';
my %a_links;
open(FILE, $filename1) or die "Could not read from $filename1, program halting.";
while(<FILE>)
{
chomp;
my @fields1 = split(/[:;]/, $_);
$a_links{$fields1[1]} = undef;
}
close FILE;
my $filename2 = 'log1';
my @fields;
open(FILE, $filename2) or die "Could not read from $filename2, program halting.";
while(<FILE>)
{
chomp;
@fields = split(/[:;]/, $_);
next if exists $a_links{$fields[1]};
print "$fields[1] \n";
}
close FILE;
Log2:
INFO @0 digrf_0_drv: Constructing a digrf Driver: digrf_0_drv; T=0
INFO @603845 mcPWM_CYC: ----- SV is waiting for FLAG 4 -----; T=603845
INFO @1116033 mcPWM_CYC: ----- SV is waiting for FLAG 0 -----; T=1116033
INFO @1145215 mcPWM_CYC: ----- Flag 0 OK SV STARTED -----; T=1145215
INFO @1145215 mcPWM_CYC: PORT STIM started !!!; T=1145215
INFO @1145287 mcPWM_CYC: ----- SV is waiting for FLAG 2 -----; T=1145287
INFO @1146281 mcPWM_CYC: ----- Flag 0 OK : SV STARTED -----; T=1146281
INFO @1146281 mcPWM_CYC: PORT STIM started !!!; T=1146281
INFO @1190554 mcPWM_CYC: C-Code exit execution. code=<aa>; T=1190554
INFO @1190554 mti_lane1_bw_mon: total bytes = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane1_bw_mon: time window = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane1_bw_mon: BW in Mbps = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane2_bw_mon: total bytes = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane2_bw_mon: time window = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane2_bw_mon: BW in Mbps = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane3_bw_mon: total bytes = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane3_bw_mon: time window = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane3_bw_mon: BW in Mbps = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane4_bw_mon: total bytes = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane4_bw_mon: time window = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane4_bw_mon: BW in Mbps = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane5_bw_mon: total bytes = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane5_bw_mon: time window = 0, at time = 1190554; T=1190554
INFO @1190554 mti_lane5_bw_mon: BW in Mbps = 0, at time = 1190554; T=1190554
INFO: Report(s) of this encapsulation run can be found under:
预期输出:
UVM_INFO @1353514 reporter [Z7_COREA]: mcPWM0_ExtSig: *** START Syncronization with Verilog Stimulus ***; T=1353514
UVM_INFO @1353578 reporter [Z7_COREA]: C FLAG_SET: Setting flag 0; T=1353578
UVM_INFO @1353578 reporter [Z7_COREA]: V FLAG_WAIT: Received flag 0; T=1353578
UVM_INFO @1353578 reporter [testbench.top_level_module.\mcPWM_CYC::main ]: ----- Flag 0 OK SV STARTED -----; T=1353578
UVM_INFO @1353578 reporter [testbench.top_level_module.\mcPWM_CYC::main ]: PORT STIM started !!!; T=1353578
UVM_INFO @1353642 reporter [Z7_COREA]: C FLAG_WAIT: Checking flag 1, status is 0; T=1353642
UVM_INFO @1353650 reporter [Z7_COREA]: V FLAG_SET: Setting flag 1; T=1353650
UVM_INFO @1353650 reporter [testbench.top_level_module.\mcPWM_CYC::main ]: ----- SV is waiting for FLAG 2 -----; T=1353650
UVM_INFO @1353650 reporter [Z4_COREA]: V FLAG_WAIT: Checking flag 2, status is 0; T=1353650
UVM_INFO @1353743 reporter [Z7_COREA]: C FLAG_WAIT: Checking flag 1, status is 1; T=1353743
UVM_INFO @1354063 reporter [Z7_COREA]: REM16: A=fbc00086 R=0007 E=0007 M=ffff; T=1354063
UVM_INFO @1354336 reporter [Z7_COREA]: REM16: A=fbc00080 R=048e E=048e M=ffff; T=1354336
UVM_INFO @1354532 reporter [Z7_COREA]: W16: A=fbc00080 W=008d; T=1354532
UVM_INFO @1354597 reporter [Z7_COREA]: C FLAG_SET: Setting flag 2; T=1354597
UVM_INFO @1354597 reporter [Z7_COREA]: V FLAG_WAIT: Received flag 2; T=1354597
UVM_INFO @1354597 reporter [testbench.top_level_module.\mcPWM_CYC::main ]: ----- Flag 0 OK SV STARTED -----; T=1354597
UVM_INFO @1354597 reporter [testbench.top_level_module.\mcPWM_CYC::main ]: PORT STIM started !!!; T=1354597
UVM_INFO @1354597 reporter [Z7_COREA]: V FLAG_WAIT: Received flag 2; T=1354597
UVM_INFO @1354597 reporter [Z7_COREA]: V FLAG_WAIT: Checking flag 2, status is 1; T=1354597
UVM_INFO @1354661 reporter [Z7_COREA]: C FLAG_WAIT: Checking flag 2, status is 1; T=1354661
UVM_INFO @1354741 reporter [Z7_COREA]: V FLAG_CLEAR: Clearing flag 2; T=1354741
UVM_INFO @1354741 reporter [Z4_COREA]: V FLAG_SET: Setting flag 5; T=1354741
UVM_INFO @1354741 reporter [Z7_COREA]: V FLAG_WAIT: Received flag 2; T=1354741
EDIT2附带的输出:
Constructing a digrf Driver: digrf_0_drv
----- SV is waiting for FLAG 4 -----
----- SV is waiting for FLAG 0 -----
C-Code exit execution. code=<aa>
total bytes = 0, at time = 1190554
time window = 0, at time = 1190554
BW in Mbps = 0, at time = 1190554
Report(s) of this encapsulation run can be found under
EDIT3附带的输出:
Constructing a digrf Driver
----- SV is waiting for FLAG 4 -----
----- SV is waiting for FLAG 0 -----
----- Flag 0 OK SV STARTED -----
PORT STIM started !!!
----- SV is waiting for FLAG 2 -----
----- Flag 0 OK
PORT STIM started !!!
C-Code exit execution. code=<aa>
total bytes = 0, at time = 1190554
time window = 0, at time = 1190554
BW in Mbps = 0, at time = 1190554
Report(s) of this encapsulation run can be found under
答案 0 :(得分:0)
尝试使用此命令行perl
perl -F"/[:;]/" -lane ' $i=$ARGV eq "log1.txt" ? 1 : 2;$F[$i]=~s/^\s*|\s*$//g;
$kv{$F[$i]}=$ARGV ; END { for(keys %kv) { print "$_" if $kv{$_} eq "log1.txt" } } '
使用您给定的输入:
$ cat log1.txt
INFO @0 digrf_0_drv: Constructing a digrf Driver: digrf_0_drv; T=0
INFO @648647 mti_disable_fuse_cov_inst: run_stimulus called; T=648647
INFO @1549325 mti_disable_fuse_cov_inst: CHECKING MTI DISABLE FUSE CONNECTED TO flash_mti_en; T=1549325
INFO @1549325 mti_disable_fuse_cov_inst: MTI_DISABLE fuse is correctly asserted ; T=1549325
$ cat log2.txt
UVM_INFO @1381068 mti_disable_fuse_cov [mti_disable_fuse_cov:INFO]: CHECKING MTI DISABLE FUSE CONNECTED TO flash_mti_en; T=1381068
UVM_INFO @1381068 mti_disable_fuse_cov [mti_disable_fuse_cov:INFO]: MTI_DISABLE fuse is correctly asserted ; T=1381068
UVM_INFO @1381068 reporter [Z7_COREB]: V FLAG_CLEAR: Clearing flag 1; T=1381068
UVM_INFO @1381068 reporter [Z4_COREA]: V FLAG_SET: Setting flag 2; T=1381068
$ perl -F"/[:;]/" -lane ' $i=$ARGV eq "log1.txt" ? 1 : 2;$F[$i]=~s/^\s*|\s*$//g;
$kv{$F[$i]}=$ARGV ; END { for(keys %kv) { print "$_" if $kv{$_} eq "log1.txt" } } ' log1.txt log2.txt
Constructing a digrf Driver
run_stimulus called
$
编辑:
要按顺序打印,请使用
perl -F"/[:;]/" -lane ' $i=$ARGV eq "log1.txt" ? 1 : 2;$F[$i]=~s/^\s*|\s*$//g;
$kv{$F[$i]}=$ARGV ;push(@f,$F[$i]) ; END { for(@f) { print "$_" if $kv{$_} eq "log1.txt" } } ' log1.txt log2.txt
EDIT2:
perl -F"/[:;]/" -lane ' $i=$ARGV eq "log1.txt" ? 1 : 2;$F[$i]=~s/^\s*|\s*$//g;
$kv{$F[$i]}=$ARGV ;push(@f,$F[$i]) ; END { for(@f) { print "$_" if $kv{$_} eq "log1.txt" } } ' log1.txt log2.txt | perl -0777 -pe ' s/(^total.*)\1//gms '
EDIT3
perl -F"/[:;]/" -lane ' $i=$ARGV eq "log1.txt" ? 1 : $#F-1; $F[$i]=~s/^\s*|\s*$//g;
$kv{$F[$i]}=$ARGV ;push(@f,$F[$i]) ; END { for(@f) { print "$_" if $kv{$_} eq "log1.txt" } } ' log1.txt log2.txt | perl -0777 -pe ' s/(^total.*)\1//gms '
EDIT4:
此解决方案完全不同于预期的输出结果
$ perl -lne ' s!:\s+(.+?)\s*(;|:$)!$x=$1;$x=~s/: //g;$kv{$x}=$ARGV!e;push(@f,$x); END { for(@f) { print "$_" if $kv{$_} eq "log1.txt" } } ' log1.txt log2.txt | perl -0777 -pe ' s/(^total.*)*(?=\1)//gms'
Constructing a digrf Driverdigrf_0_drv
----- SV is waiting for FLAG 4 -----
----- SV is waiting for FLAG 0 -----
C-Code exit execution. code=<aa>
total bytes = 0, at time = 1190554
time window = 0, at time = 1190554
BW in Mbps = 0, at time = 1190554
Report(s) of this encapsulation run can be found under
$
注意事项:
----- Flag 0 OK : SV STARTED ----- => log1.txt
----- Flag 0 OK SV STARTED ----- => log2.txt
以上两行完全不同,因此我必须在替换过程中删除“:”以匹配并消除它们以获得所需的输出
log1.txt中的最后一行
INFO: Report(s) of this encapsulation run can be found under:
没有分号,因此我在正则表达式匹配项中使用|:$
进行了调整。
希望这会有所帮助