renjoooz has asked for the wisdom of the Perl Monks concerning the following question:
I have 2 log files as given below.Both files have some things in common.I need 1 file having the common items and another file having items which are not common to both. Thanks in advance.
FILE1: <CMD> deselectAll <CMD> uiSetTool ruler <CMD> uiSetTool select dummy_core/pads/dfdtghj_op dummy_core/pads/fghf_bg <CMD> windowSelect 5522.2554.33654.256552.44 <CMD> spaceObject -fixSide bottom -space 0 Spacing instances ... selected instances/modules: dummy_core/pads/xx dummy_core/pads/hg_2 dummy_core/pads/dhghj_uu <CMD> deselectAll <CMD> selectInst core/pads/IO_gnd_right18 <CMD> selectInst core/pads/IO_vdd_right18 <CMD> uiSetTool move5 dummy_core/pads/gh_5 dummycore/pads/ghjk_0 dummy_core/pads/ghjk_8 FILE2: 1. this file is for error checking 2. this file is for error checking dummy_core/pads/dfdtghj_op dummy_core/pads/fghf_bg dummy_core/pads/xx dummy_core/pads/hg_2 <CMD> utTl ruler <CMD> utTl select dummy_core/pads/dhghj_uu dummy_core/pads/gh_5 dummycore/pads/ghjk_0 pads/fghf_bg pads/dhghj_u dummy_core/pads/ghjk_8 RESULT NOTCOMMON: <CMD> deselectAll <CMD> uiSetTool ruler <CMD> uiSetTool select <CMD> windowSelect 5522.2554.33654.256552.44 <CMD> spaceObject -fixSide bottom -space 0 Spacing instances ... selected instances/modules: <CMD> deselectAll <CMD> selectInst core/pads/IO_gnd_right18 <CMD> selectInst core/pads/IO_vdd_right18 <CMD> uiSetTool move5 1. this file is for error checking 2. this file is for error checking <CMD> utTl ruler <CMD> utTl select pads/fghf_bg pads/dhghj_u RESULT COMMON: dummy_core/pads/dfdtghj_op dummy_core/pads/fghf_bg dummy_core/pads/xx dummy_core/pads/hg_2 dummy_core/pads/dhghj_uu dummy_core/pads/gh_5 dummycore/pads/ghjk_0 dummy_core/pads/ghjk_8
I have tried different ways to get the result...but none of them was successful... I am providing some of the codes i have tried
#!/usr/bin/perl $fnx = "/home/perl/t1x.g"; $fny = "/home/perl/t25y.g"; $fnz = "/home/perl/t22z.g"; $fntmp = "/home/perl/t22tmp.g"; open FPX, "$fnx" or die "Error in write:$!"; open FPY, "$fny" or die "Error in write:$!"; open FPZ, ">$fnz" or die "Error in write:$!"; open FPTMP, ">$fntmp" or die "Error in write:$!"; while (<FPX>) { @x_line = $_; while (<FPY>) { if($_ == @x_line){ print "Saving matched at $.\n"; print FPTMP "$_ \n"; } else{ print "Saving unmatched at $.\n"; print FPZ "$_ \n"; } } } close FPX; close FPY; close FPZ; #!/usr/bin/perl $fnx = "/home/perl/t1x.g"; $fny = "/home/perl/t25y.g"; $fnz = "/home/perl/t22z.g"; $fntmp = "/home/perl/t22tmp.g"; open FPX, "$fnx" or die "Error in write:$!"; open FPZ, ">$fnz" or die "Error in write:$!"; open FPTMP, ">$fntmp" or die "Error in write:$!"; XFILE: $flag = 0; while ($x_line = <FPX>) { open FPY, "$fny" or die "Error in write:$!"; while ($y_line = <FPY>) { if($y_line eq $x_line) { print "Match found at $y_line\n"; print FPTMP "$y_line\n"; $flag = 1; next XFILE; } else { print "Match not found at $.\n"; next; } } if ($flag == 0) { print "Some Match not found at $x_line\n"; print FPZ "$x_line\n"; } close FPY; } close FPX; close FPZ; close FPTMP; #!/usr/bin/perl $fnx = "/home/perl/t1x.g"; $fny = "/home/perl/t25y.g"; $fnz = "/home/perl/t22z.g"; $fntmp = "/home/perl/t22tmp.g"; open FPX, "$fnx" or die "Error in write:$!"; open FPY, "$fny" or die "Error in write:$!"; open FPZ, ">$fnz" or die "Error in write:$!"; open FPTMP, ">$fntmp" or die "Error in write:$!"; while (<FPX>) { @x_line = $_; while (<FPY>) { if($_ =~ m/@x_line/){ @bb = m/@x_line/; print FPTMP "@bb\n"; next; } else { print FPZ "@x_line"; next; } } } close FPX; close FPY; close FPZ; #!/usr/bin/perl $fnx = "/home/t1x.g"; $fny = "/home/t25y.g"; $fnz = "/home/t22z.g"; $fntmp = "/home/t22tmp.g"; open FPX, "$fnx" or die "couldn't open $fnx: $!"; open FPZ, ">$fnz" or die "couldn't open $fnz: $!"; open FPTMP, ">$fntmp" or die "couldn't open $fntmp: $!"; XFILE:while (@x_line = <FPX>) { open FPY, "$fny" or die "Error in write:$!"; while (@y_line = <FPY>) { if (@x_line eq @y_line){ print FPTMP "@x_line\n"; goto XFILE; } else{ print FPZ "@y_line\n"; } } close FPY; } close FPX; close FPZ; close FPTMP;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Need help for extracting Log file using Perl script
by McA (Priest) on Sep 25, 2012 at 13:26 UTC | |
Re: Need help for extracting Log file using Perl script
by grizzley (Chaplain) on Sep 25, 2012 at 13:31 UTC |
Back to
Seekers of Perl Wisdom