Hello.. I have just begun to learn perl. I'm trying to compare the contents in 2 files and print the missing information.
-dnstemplate.txt- --------
<template:cisco:dns>
ip domain-name fanniemae.com
ip name-server 192.168.3.71
ip name-server 158.137.21.80
ip name-server 158.137.218.75
<end>
<template:cat:dns>
set ip dns server 192.168.3.71 primary
set ip dns server 158.137.218.75
set ip dns server 158.137.21.80
set ip dns enable
set ip dns domain fanniemae.com
<end>
----------------------------------------
-rconfig.txt-----
9acd-ra01.1192598100
version 12.2
vtp enabled
ip domain-name fanniemae.com
ip name-server 192.168.3.71
ip name-server 158.137.21.71
ip name-server 158.137.21.80
ip name-server 158.137.218.75
--------------------------------
Here's my script:
Difference.pl
#!/usr/bin/perl
open(DNS,"dnstemplate.txt");
open(RCONFIG,"rconfig.txt");
@dns=<DNS>;
@rconfig=<RCONFIG>;
my %seen; #lookup table
#build lookup table
@seen{@rconfig}=();
foreach $item(@dns)
{
push(@miss,$item) unless exists $seen{$item};
}
foreach(@miss)
{
print "Difference is $_";
}
close(DNS);
close(RCONFIG);
----------------------
This gives me the difference, but i want to compare the lines within the tags <template:cisco:dns> and <end> of dnstemplate.txt with rconfig.txt
Can you guys help me out on this one?
Thanks.
-dnstemplate.txt- --------
<template:cisco:dns>
ip domain-name fanniemae.com
ip name-server 192.168.3.71
ip name-server 158.137.21.80
ip name-server 158.137.218.75
<end>
<template:cat:dns>
set ip dns server 192.168.3.71 primary
set ip dns server 158.137.218.75
set ip dns server 158.137.21.80
set ip dns enable
set ip dns domain fanniemae.com
<end>
----------------------------------------
-rconfig.txt-----
9acd-ra01.1192598100
version 12.2
vtp enabled
ip domain-name fanniemae.com
ip name-server 192.168.3.71
ip name-server 158.137.21.71
ip name-server 158.137.21.80
ip name-server 158.137.218.75
--------------------------------
Here's my script:
Difference.pl
#!/usr/bin/perl
open(DNS,"dnstemplate.txt");
open(RCONFIG,"rconfig.txt");
@dns=<DNS>;
@rconfig=<RCONFIG>;
my %seen; #lookup table
#build lookup table
@seen{@rconfig}=();
foreach $item(@dns)
{
push(@miss,$item) unless exists $seen{$item};
}
foreach(@miss)
{
print "Difference is $_";
}
close(DNS);
close(RCONFIG);
----------------------
This gives me the difference, but i want to compare the lines within the tags <template:cisco:dns> and <end> of dnstemplate.txt with rconfig.txt
Can you guys help me out on this one?
Thanks.