I have two files.File1 contains
470.2843 organism AR_0036 123 Intermediate
470.2845 organism AR_0033 456 Susceptible
903909.3 organism Naval-83 789 Resistant
and file2 contains
123
456
abc
def
789
I want my output such that: if in file2 values do not match with file1, perl leaves those lines blank in the output file; or if it matches, then print the corresponding data of the matched line in the output file.
#!/usr/bin/perl
my $file1 = '/Users/apple/Desktop/ncbi_ab_data/new_file1';
my $file2 = '/Users/apple/Desktop/ncbi_ab_data/new_file2';
open my $fh1, '<' , $file1;
while (<$fh1>){
chomp;
my @file1 = split('\t', $_ );
#print "$file1[0]\t";
#print "$file1[1]\t";
#print "$file1[2]\t";
#print "$file1[3]\t\n";
open my $fh2, '<' , $file2;
while (<$fh2>){
chomp;
my @file2 = split('\t', $_ );
#if ($file2[0] == $file1[2])
#print "$file2[0]\n";
if ($file2[0] = $file1[2]){
print "$file2[0]";
print "\t$file1[3]\n";
}
#print "$file1[0]\n";
#print "$file2[1]\n";
#print "$file2[2]\n";
#print "$file2[3]\n";
#print "$file2[4]\n";
}
}
I have written this code but it doesn't work properly.