Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Parsing cisco router command output (potential answer, untested)

by ybiC (Prior)
on Mar 14, 2003 at 20:03 UTC ( #243163=note: print w/ replies, xml ) Need Help??


in reply to Parsing cisco router command output

  Hiya routedude,
I added <code> tags around your example code, and tweaked some to make it clearer to my short-bus brain.   I found this syntax for matching-the-intersection-of-two-arrays on page 106 of The Perl Cookbook, and also moved the file opens/closes as close to each ofther as possible - always a good habit.
 
Anyways, I *think* this will do what you want or at least be close.   Wiser monks than I might show how to make it scale to more than just two days' acl log files.   The 'while... push unless /matches/' chunks could likely become a subroutine, but as is, this maybe shows some direction.
  cheers,
  ybiC
    striving toward Perl Adept
    (it's pronounced "why-bick")

==untested==
#/usr/bin/perl -w use strict; # define output+input filenames: my $outFile = 'aclLog.txt'; print "Enter filename that contains output of show access <list\n"; chomp my $aclMatchesDay2 = <STDIN>; print "Enter the second file\n"; chomp my $aclMatchesDay2 = <STDIN>; # check for no-matches in first input file: open (ACLM1, $aclMatchesDay1) or die "Couldn't open $aclMatchesDay1: $ +!"; while (<ACLM1>){ push @noMatchesDay1 unless /matches/; } close ACLM1 or die "Couldn't close $aclMatchesDay1: $!"; # check for no-matches in second input file: open (ACLM2, $aclMatchesDay2) or die "Couldn't open $aclMatchesDay2: $ +!"; while (<ACLM2>){ push @noMatchesDay2 unless /matches/; } close ACLM2 or die "Couldn't close $aclMatchesDay2: $!"; # check for overlap betwixt two input files: my %isect; foreach $e (@noMatchesDay1, @noMatchesDay2){ $isect{$e}++; } my $noMatchesEver = keys %isect; # print said overlap to output file: open (OUT, ">>$outFile") or die "Couldn't open $outFile: $!"; print "$_\n" for @noMatchesEver; close OUT or die "Couldn't close $$outFile: $!";


Comment on Re: Parsing cisco router command output (potential answer, untested)
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://243163]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (7)
As of 2014-12-26 04:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (165 votes), past polls