Application, This occured blah
Application, That occured blah
Application, Also this
AnotherLog, Bob did this
AnotherLog, Dave did that
FileB.log:
Uk, London, Application, datetime, LaterDateTime, Today it had'nt occured blah but I dont care
Uk, London, Application, datetime, LaterDateTime, Today This occured blah and I care
USA, Texas, Application, datetime, LaterDateTime, Today This may have occured blah but I dont care
From Perl, how can I print out to another file, where colum[0] and colum[1] from FileA have occured in colum[3] and colum[6] from FileB - notice that comun[6] may have part of the string.
I'd like to print each line where the columns match, so for example the result will show something like this:
to OUTPUTfile.log:
Uk, London, Application, datetime, LaterDateTime, Today This occured blah and I care
Because it had the work 'application' which matched the string from the other file in colum[0] (in fileB), and it contained the string ' This occured blah ' which occured in column[5] (in fileB).
$ head File[AB].log
==> FileA.log <==
Application, This occured blah
Application, That occured blah
Application, Also this
AnotherLog, Bob did this
AnotherLog, Dave did that
==> FileB.log <==
Uk, London, Application, datetime, LaterDateTime, Today it had'nt occured blah but I dont care
Uk, London, Application, datetime, LaterDateTime, Today This occured blah and I care
USA, Texas, Application, datetime, LaterDateTime, Today This may have occured blah but I dont care
$ cat script.pl
use warnings;
use strict;
die qq[Usage: perl $0 <fileA> <fileB>\n] unless @ARGV == 2;
my $file_in_process = 1;
my %fileA;
while ( <> ) {
next if m/\A\s*\Z/;
chomp;
my @f = split /\s*,\s*/;
if ( $file_in_process == 1 ) {
next unless @f == 2;
push @{ $fileA{ $f[0] } }, $f[1];
next;
}
if ( exists $fileA{ $f[2] } and grep { $f[5] =~ m/$_/ } @{ $fileA{ $f[2] } } ) {
printf qq[%s\n], $_;
}
}
continue {
if ( eof ) {
++$file_in_process;
}
}
$ perl script.pl File[AB].log
Uk, London, Application, datetime, LaterDateTime, Today This occured blah and I care