Dear All
I have two files having values like this:
File1:
10.1103/PhysRevA.10.2325 1
10.1103/PhysRevLett.32.584 2
10.1103/PhysRevB.13.4845 3
File 2:
having comma separated values like this:
10.1103/PhysRevA.10.2325,10.1103/PhysRevLett.32.584
10.1103/PhysRevB.13.4845,10.1103/PhysRevLett.32.584
I want the result two be like this:
1 2
3 2
I am using this code but have not be able to successfully do what I have mentioned above:
#!usr/bin/perl
use warnings;
use strict;
my $input = 'file1.txt';
my $input2 = 'file2.csv';
my $output = 'output.txt';
our(@aj1,@aj2,@aj3,@aj4);
open(INFILE, "<$input") or die "Couldn't open $input for reading: $!";
open(INFILE2, "<$input2") or die "Couldn't open $input2 for reading: $!";
open(OUTFILE, ">$output") or die "Couldn't open $output for writing: $!";
while(<INFILE>)
{
my $line= $_;
$line=~tr/\n//d;
my($hits1,$hits2)=(split("\t",$line))[0,1];
push(@aj1,"$hits1");
push(@aj2,"$hits2");
}
my $size= $#aj1;
while(<INFILE2>)
{
my $c = 0;
my $lines= $_;
chomp($lines);
my($hits3,$hits4)=(split("\,",$lines))[0,1];
print "$hits3\t";
for(my $i=0;$i<$size;$i++)
{
my $a= $aj1[$i];
my $b= $aj2[$i];
if ($hits3 =~ m/($hits3)/)
{
print OUTFILE"$b";
print "$a\n";
}
elsif ($a =~ m/($hits4)/)
{
$c=$b;
}
}
print OUTFILE"\t$c\n";
}
close(INFILE);
close(OUTFILE);
Can somebody suggest me what should I do so that I can get the desired output. Thanks!!
Best
Aj