Code:
#! /opt/third-party/bin/perl
open(FILE, "<", secondfile) || die ("Unable to open secondfile. <$!>\n");
while( <FILE> ) {
chomp;
@split_arr = split(/ /, $_);
my $dump;
for( my $i = 1; $i <= $#split_arr; $i++ ) {
$dump .= ( $split_arr[$i] . ":");
}
$dump =~ s/:$//;
$fileHash{$split_arr[0]} = $dump;
}
close(FILE);
open(FILE, "<", firstfile) || die ("Unable to open firstfile. <$!>\n");
while( <FILE> ) {
chomp;
@first_arr = split(/ /, $_);
print "$first_arr[0] ";
foreach my $key ( keys %fileHash ) {
@second_arr = split(/:/, $fileHash{$key});
for($i = 0; $i <= $#second_arr; $i++ ) {
$set = 0;
for( $j = 1; $j <= $#first_arr; $j++ ) {
if( $first_arr[$j] =~ $second_arr[$i] ) {
$set = 1;
last;
}
}
last if( $set == 0 && $#first_arr > 1 )
}
print "$key " if( $set == 1 )
}
print "\n";
}
close(FILE);
exit 0
Quote:
Verified two sources of input,
hopefully it should work properly now! 
Give it a shot!
Sorry for not being up to the point in the beginning itself!
|
Its working fine but got one problem. I think I mentioned it on the thread that it's looking for a file pattern not the exact word. Please see below:
File1
AAABB370 MI_AP MI_RC
MI_REC_DUP VIEW
AAABB371 VIEW
AAABB372 MI_UNIT VIEW
AAABB373 REQUEST APPROVE INQUIRE
AAABB374 REQUEST APPROVE MI_AP MI_RC MI_REC VIEW
File2
role1 MI_RC MI_REC
role2 MI_AP MI_REC
role3 VIEW
role4 VIEW MI_UNIT
role5 REQUEST APPROVE INQUIRE
role6 REQUEST
Code Output:
AAABB370 role1 role3 role2
AAABB371 role3
AAABB372 role3 role4
AAABB373 role6 role5
AAABB374 role1 role3 role6 role2
Needed Output:
AAABB370 role3 role2
AAABB371 role3
AAABB372 role3 role4
AAABB373 role6 role5
AAABB374 role3 role6 role2