jorain has asked for the wisdom of the Perl Monks concerning the following question:
<readme> Need to have a script that will match the ip 138.63.20.48 with the company7 info in file 2. Code is started and looks like this: </readme>File1 138.63.20.48 63.208.170.231 132.3.0.193 63.208.170.198 63.236.1.136 63.236.1.139 205.161.5.239 The second file looks like this: File2 Company1-100.45.0.0-100.45.255.255 Company2-227.133.171.0-227.133.173.0 Company3-63.208.170.5-63.208.170.254 Company4-95.214.36.0-95.214.39.255 Company5-35.117.181.0-35.117.181.127 Company6-55.207.128.0-55.207.143.255 Company7-138.63.20.12-138.63.20.95
<readme> Would appreciate any help </readme>open (IP1,"ipsnew.txt"); open (WHERE,"whereby.txt"); while (<IP1>) { if (/^(.*?)(\d+\.\d+\.\d+)(.*?)$/) { $beg_line1{2} = $1; $ip1 = $2; # print IP1 "$ip1\n"; # print "@ip1\n"; } } while (<WHERE>) { if (/^(.*?)(\d+\.\d+\.\d+)(.*?)$/) { $beg_line2 = $1; $ip2 = $2; # print IP1 "$ip1\n"; # print "@ip2\n"; } } if ($beg_line1{$ip1} == $beg_line2{$ip2}) { print "we have a match at $ip1\n";}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Compare two files (Ip addresses)
by NetWallah (Canon) on May 16, 2007 at 05:03 UTC | |
|
Re: Compare two files (Ip addresses)
by graff (Chancellor) on May 16, 2007 at 02:23 UTC | |
|
Re: Compare two files (Ip addresses)
by thezip (Vicar) on May 15, 2007 at 22:52 UTC |