Help cross-referencing files
David Nicol
davidnicol at gmail.com
Mon Apr 18 20:48:03 CDT 2005
On 4/18/05, Brad <brad at bradandkim.net> wrote:
> Hi all,
>
> I have 3 files each of which are space delimited sets of data. I have
> to cross-reference these files to get one set of data at the end. The
> first file maps IP Address to Cisco ATM interface, the second maps IP
> Address to MAC Address, and the third maps Cisco ATM interface to actual
> VPI and VCI. I need to map MAC Address to VCI/VPI. Here is a sample of
> each file:
>
> 24.121.58.91 0.32
ip to if
> 24.121.57.11 0100.0f66.2b81.5f
mac to ip
> 0.2 1 33
if to data
>
> I was thinking of using awk, but I am not sure how to tell awk to keep
> an array for each line of 2 files (let alone 3). Any shell script
> guru's care to lend some advice?
perl's associative arrays are ideal for this kind of thing,
especially coupled with its easy line-based file primitives.
open IP2IF, "ip_to_interface_file";
while (<IP2IF>){
/([0123456789\.]+)\s+([0123456789\.]+) or next;
$ip2if{$1} = $2;
};
repeat something like that for all three, then
for (keys %mac2ip){
print "Mac Address $_ is handled on ",
"Vdata $if2data{$ip2if{$mac2ip{$_}}}\n";
};
hope that helps
--
David L Nicol
$SesKey=join"",grep{/\w/}map{chr rand 128}0..99;#Zesty!
More information about the Kclug
mailing list