...etc1.10.10 1.10.1040 1.10.150 1.10.220
and another that looks like this (FILE2)
...etc1.10.10.640 1.10.10.650 1.10.10.660 1.10.1040.20 1.10.150.290 1.10.150.300 1.10.150.310 1.10.220.80
I'm wanting to match the first three numbers from the 4 number strings in FILE2 (each number being separated by a '.') with the corresponding three number strings in FILE1 and then count how many matches there are.
For example for the three number string 1.10.10 in FILE1 there are 3 matches in FILE2.
I want the output file to look like this:
I've got the following script1.10.10 3 1.10.1040 1 1.10.150 3 1.10.220 1
But its simply not working properly - its not finding all the matches. I've given only example files here - the actual files are much bigger - some matches are recognised but not all. Any pointers in the right direction much appreciated!!!use strict; my $file1 = shift; my $file2 = shift; open(FILE1, $file1) or die "Cant open $file1:$!\n"; open(FILE2, $file2) or die "Cant open $file2:$!\n"; my @file1 =<FILE1>; my @file2 =<FILE2>; #print @file1; #print @file2; for(my $i=0; $i<@file1; $i++) { chop($file1[$i]); #print "F $file1[$i]"; for(my $j=0; $j<@file2; $j++) { chop($file2[$j]); my @array = split(/\./, $file2[$j]); my $cat = "$array[0]" . "." . "$array[1]" . "." . "$array[2]"; if("$file1[$i]" eq "$cat") { print "$file1[$i] $cat\n"; } } }
In reply to help requested with collating data from two files by Angharad
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |