D
david
Im trying to parse a file with data such as this:
(ip's changed for obvious reasons)
acl add table=ipaddr name=127.0.0.1 burb=Firewall \
comments='Firewall network object for DNS proxy ACL redirection' \
lastchangedby='root on 08/12/02 13:36:23'
acl add table=ipaddr name=127.1.1.1 burb=external \
lastchangedby='dlepage on 06/24/03 10:25:30'
I want the end output to look like:
acl add name=127.0.0.1 ipaddr=127.0.0.1 comments='Firewall network
object for DNS proxy ACL redirection'
acl add name=127.1.1.1 ipaddr=127.1.1.1 comments=
so basically I only want to capture the IP after the 'name=' value,
and anything in the 'comments' field, if at all. Here is what I have
so far, which works, but im so new to programming that I know my
coding stinks. Any suggestions to make this more efficient
appreciated.
#!/usr/bin/perl -w
use strict;
my ($ip,$comment);
open(IN, "<$ARGV[0]") || die "Cant open $!";
flock (IN, 1);
while( <IN> ) {
s/\\//g; # get rid of newlines
# match on acl's with comments
if (/^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+) burb=(.+)
comments=
(.+)/) {
print "acl add name=$1 ipaddr=$1 comments=$3\n";
}
# else match without comments
elsif (/^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+)
burb=(.+)$/) {
print "acl add name=$1 ipaddr=$1 comments=\n";
}
}
close(IN);
-d
(ip's changed for obvious reasons)
acl add table=ipaddr name=127.0.0.1 burb=Firewall \
comments='Firewall network object for DNS proxy ACL redirection' \
lastchangedby='root on 08/12/02 13:36:23'
acl add table=ipaddr name=127.1.1.1 burb=external \
lastchangedby='dlepage on 06/24/03 10:25:30'
I want the end output to look like:
acl add name=127.0.0.1 ipaddr=127.0.0.1 comments='Firewall network
object for DNS proxy ACL redirection'
acl add name=127.1.1.1 ipaddr=127.1.1.1 comments=
so basically I only want to capture the IP after the 'name=' value,
and anything in the 'comments' field, if at all. Here is what I have
so far, which works, but im so new to programming that I know my
coding stinks. Any suggestions to make this more efficient
appreciated.
#!/usr/bin/perl -w
use strict;
my ($ip,$comment);
open(IN, "<$ARGV[0]") || die "Cant open $!";
flock (IN, 1);
while( <IN> ) {
s/\\//g; # get rid of newlines
# match on acl's with comments
if (/^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+) burb=(.+)
comments=
(.+)/) {
print "acl add name=$1 ipaddr=$1 comments=$3\n";
}
# else match without comments
elsif (/^acl add table=ipaddr name=(\d+\.\d+\.\d+\.\d+)
burb=(.+)$/) {
print "acl add name=$1 ipaddr=$1 comments=\n";
}
}
close(IN);
-d