Print lines based on matching words.
This is what I have so far.
while (<DATA>) {
/object-group\s/;
# print the next word followed by object-group
my @after=split(/\s/,$');
my @array = $after[0];
# unique array NOT working......
my @unique = do { my %seen; grep { !$seen{$_}++ } @array };
foreach my $var ( @unique ) {
# remove word - network
if ($var !~ m/network/) {
# remove word - service
next if ($var =~ m/service/);
print $var, "\n";
}
}
}
__DATA__
access-list INSIDE_IN remark Web Users To Web Server
access-list INSIDE_IN extended permit tcp object-group WEB-CLIENT obje
+ct-group WEB-SERVER object-group WEB_TCP
access-list INSIDE_IN remark EMAIL To EMAIL Server
access-list INSIDE_IN extended permit tcp object-group EMAIL-CLIENT ob
+ject-group EMAIL-SERVER object-group SMTP_TCP
object-group network PC1_1st
network-object host 10.1.1.11
object-group network PC2_1st
network-object host 10.1.1.12
object-group network WEB-CLIENT
group-object PC1_1st
group-object PC2_1st
object-group network WEB-SERVER
network-object host 10.1.1.5
object-group service WEB_TCP tcp
port-object eq www
port-object eq https
object-group network EMAIL-CLIENT
group-object PC1_1st
group-object PC2_1st
object-group network EMAIL-SERVER
network-object host 10.1.1.6
object-group service SMTP_TCP tcp
port-object eq SMTP
I am trying to print the lines that matches with given strings.
For example:
access-list INSIDE_IN extended permit tcp object-group WEB-CLIENT obje
+ct-group WEB-SERVER object-group WEB_TCP<br>
-will take WEB-CLIENT, WEB-SERVER, WEB_TCP, etc. and under those PC1_1st & PC2_1st etc., to match and then print as following-
Ignore the Line with word - remark.
access-list INSIDE_IN extended permit tcp object-group WEB-CLIENT obje
+ct-group WEB-SERVER object-group WEB_TCP
object-group network WEB-CLIENT
group-object PC1_1st
group-object PC2_1st
object-group network PC1_1st
network-object host 10.1.1.11
object-group network PC2_1st
network-object host 10.1.1.12
object-group network WEB-SERVER
network-object host 10.1.1.5
object-group service WEB_TCP tcp
port-object eq www
port-object eq https
For the 2nd matching---
access-list INSIDE_IN extended permit tcp object-group EMAIL-CLIENT ob
+ject-group EMAIL-SERVER object-group SMTP_TCP
object-group network EMAIL-CLIENT
group-object PC1_1st
group-object PC2_1st
object-group network PC1_1st
network-object host 10.1.1.11
object-group network PC2_1st
network-object host 10.1.1.12
object-group network EMAIL-SERVER
network-object host 10.1.1.6
object-group service SMTP_TCP tcp
port-object eq SMTP
Please let me know.