Captainrave
Technical User
Hi all,
I ran into a huge problem with my work today and think a Perl script will fix it and hopefully save me weeks of tedious work (and needless to say get the boss off my back!). Basically I am stuck comparing two files.
The first has two columns that look like:
3254 5041
8277 9047
9052 10056
10053 10427
10431 11270
11271 12011
The second has many columns that look like:
AAAAAA 443 526 511 516 513.5
TTTTT 629 1648 669 673 671
AAAAA 629 1648 694 698 696
AAAAA 629 1648 863 867 865
AAAAA 629 1648 894 898 896
If the number in the 1st column of the 1st file matches a number in the 2nd column of the 2nd file I want to save that entire line of the 2nd file (I assume to a new "outfile). So something like:
Problem is it has been a long while since I last wrote Perl script. Any help would be very much appreciated!!!
I ran into a huge problem with my work today and think a Perl script will fix it and hopefully save me weeks of tedious work (and needless to say get the boss off my back!). Basically I am stuck comparing two files.
The first has two columns that look like:
3254 5041
8277 9047
9052 10056
10053 10427
10431 11270
11271 12011
The second has many columns that look like:
AAAAAA 443 526 511 516 513.5
TTTTT 629 1648 669 673 671
AAAAA 629 1648 694 698 696
AAAAA 629 1648 863 867 865
AAAAA 629 1648 894 898 896
If the number in the 1st column of the 1st file matches a number in the 2nd column of the 2nd file I want to save that entire line of the 2nd file (I assume to a new "outfile). So something like:
Code:
#!C:/Perl/bin/perl.exe -w
#Opening the CDS location file
print "Please type the filename of the CDS_LOCATION.xls file:";
$File1 = <STDIN>;
chomp $File1;
#Opening Comparison file
print "please type the filename of the comparison.csv file:";
$File2 = <STDIN>;
chomp $File2;
print "please type the filename to save the results to (.csv format !!important!!):";
$outfile = <STDIN>;
chomp $outfile;
open(CDSFILE,$File1);
open(COMPARISONFILE, $File2);
open(OUTFILE,">$outfile");
###########################
# Output #
###########################
while(<CDSFILE>){
chomp;
If CDSFile column 1 = COMPARISONFILE column 2
print that line of COMPARISONFILE to OUTFILE;
}
exit;
Problem is it has been a long while since I last wrote Perl script. Any help would be very much appreciated!!!