loop issue

I have 2 files one of them has all the all mac addresses and the other one has all the ip addresses. Basically, I want to loop thru those 2 files and generate a configuration like below:

host www184.domain.com {
hardware ethernet 00:13:72:3B:B4:3A;
fixed-address 192.168.0.184;
}

any feedbacks?

Thanks

Hi !

Asuming that you are sure that you have the same number of lines on both files, and every record is on a single line, you can use the following script:

#!/usr/bin/perl -w
#

open(MACS,"mac.txt") or die("Could not open mac.txt");
open(IPS,"ip.txt") or die("Could not open ip.txt");
open(RESULT,">result.txt") or die("Could not open result.txt");

my @macs = ();
my @ips = ();

push(@macs,$_) while( <MACS> );
push(@ips,$_)  while( <IPS> );

chomp(@macs);
chomp(@ips);

for( $i=0 ; $i<=$#macs ; $i++ ){
    print RESULT "host www$i.domain.com {\n";
    print RESULT "hardware ethernet $macs[$i];\n";
    print RESULT "fixed-address $ips[$i];\n";
    print RESULT  "}\n\n";
}

close(MACS);
close(IPS);
close(RESULT);

Is the hostname common to both files?

Thanks for the script. It works great...

The hostname is actually the last octet of the ip. I ended up creating a separate hostname file and was able to get the final result with Sergiu-IT's script.