I'm not sure I've understood your question, but time will tell..
First of all I think you need some advice on syntax: in order of importance @arr & @arr2
perl -E "@a1=qw(1 2 3); @a2=qw(a b c d e); say for (@a1 & @a2)" 1 perl -E "@a1=qw(1 2 3); @a2=qw(a b c d e); say for (@a1 , @a2)" 1 2 3 a b c d e
Infact to concatenate two list in list context the comma is used not & see perlop
Then your way to open filehandle, while running, is oldish and error prone:
open(FILE, "<x.log"); close (FILE); # has to be open my $file_handle, '<', 'x.log' or die "unable to open 'x.log' $!"; .. close $file_handle;
Third, you are reassigning twice to @array2 = grep .. and, as long as you print to the destination file immediately, can also be what your intended, but is not clear and error prone in long distance: grep in list context will returns a list and you can use push to extend the array:
my @array; ... #push 1 push @array, $_ for grep{.. #push 2 push @array, $_ for grep{..
Also please use <code> ..code tags.. </code> also for your data input/output
PS After reading twice, please clearify the following:
> Now I want to compare the data present after the keyword following colon(:) and in output file I have to print the mismatched lines from first data-set on comparing it with second data-set and number of lines in second data set that are not present in first data-set.
If I understand what you are asking for I'd go with a datastructure like a hash of arrays, which keys will be all keywords occurences and array element populed by the evntual presence in file 1 and file 2:
# pseudocode my %report; foreach my $line( $fh_one ){ if... matching.. extract the part interesting $report{ $interesting_part }[0] = 1; # first file populates the +element 0 foreach my $line( $fh_two ){ if... matching.. extract the part interesting $report{ $interesting_part }[1] = 1; # first file populates the +element 1 # result like %report = ( interesting1 = [ undef, 1 ], # is present only in the second file interesting2 = [ 1, undef ], # is present only in the first file interesting3 = [ 1, 1 ], # is present in both files );
L*
In reply to Re: Compare two log files line by line containing a keyword
by Discipulus
in thread Compare two log files line by line containing a keyword
by rahu_6697
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |