ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I am only interested in the interfaces that have an IP address(like Serial1/1.1/19:0.1 above) when I use the following code and push my matches to an array
Code:
my ($lines,$hostname,@int,@ip);
open(CONFIGURATIONS,"/var/random/ni/test") or die "couldn't open configurations";
while (<CONFIGURATIONS>) {
chomp;
$lines = $_;
if ($lines =~ /interface (\S+)(?:.*)?/) {
push @int,$1;
}
if ($lines =~ /^ (ip address ((?:\d{1,3}\.){3}\d) (?:\d{1,3}\.){3}\d)/) {
my $ips = $1;
push @ip,$ips;
}
}
for (my $x=0;$x < scalar(@int) ; $x++) {
if (defined $ip[$x]) {
print "$int[$x] $ip[$x]\n";
}
}
close CONFIGURATIONS;
This is what happens:
Quote:
./dns.pl
Serial1/1.1/19:0 ip address 10.136.18.1 255.255.255.2
spits out the wrong interface I am expecting Serial1/1.1/19:0.1 since that IP is under it. Anyway, I was trying a new record separator since each block of interfaces seems to be separated by ! but that didn't do the trick or I may have been using it incorrectly.
Anyone?
Except it doesn't do what was asked. The OP apparently wants a single line of "<interface> <IP @/netmask>", but only <if IP @> is really an IP address.
IMHO (s)he is 95% there - just a small matter to resolve (instead of printing elements, print the arrays and see what you get).
Last edited by syg00; 07-24-2008 at 05:19 PM.
Reason: hint added
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.