#!/usr/bin/perl use strict; use warnings; my $PolicyName = ""; my $PolicyType = ""; my $ActivePolicy = ""; my $ClientServer = ""; open(INFILE, '<mas01_policy_dump.txt'); while(<INFILE>) { chomp; if ( /^\s*$/ ) { # true when the current line is blank next; # No need to process blank lines here } if ( /------------------------------------------------------------ +/) { # Print all the seperators print "$_\n"; next; # No need for further checks } if ($_ =~ "Policy Name") { $PolicyName = $_; # New Policy, pay attention next; } if ($_ =~ "Policy Type") { $PolicyType = $_; next; } if ($_ =~ "Active") { if ($_ =~ "yes") { # Active Policy, we want this stuff $ActivePolicy = $_; print "$PolicyName\n"; print "$PolicyType\n"; print "$ActivePolicy\n"; next; } else { # Inactive policy, skip ahead while(<INFILE>) { if ( /------------------------------------------------ +------------/) { print $_; # CRLF included since no chomp last; } } } } # So should be active policy and non blank line from here if ($_ =~ "HW/OS/Client" ) { # Mutliline!! print "$_\n"; while(<INFILE>) { if ( /^\s*$/ ) { last; } # Blank line = end of lines chomp; print "$_\n"; } next; # I should hit this line only when $_ is blank } }
In reply to Re^4: How to print certain lines out of a text file.
by sawdustar
in thread How to print certain lines out of a text file.
by sawdustar
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |