I am trying to use variables to hold the regex exppression to make it easier to code, and I'm running into one issue parsing firewall logs.
When I call the same regex variable multiple times the first group returns the correct result but the second one shows part of the first IP address.
-- Sample data Mar 10 07:42:38 DR-FW-1 : %ASA-6-305011: Built dynamic UDP translation from inside:172.28.17.130/3324 to outside(internet-traffic):69.176.102.83/24295
output:
re1 -> 172.28.17.130
re2 -> 17.
------------------------------------------
my $Raw_Log = "";
my $re_ipv4 = qr/(([2]([0-4][0-9]|[5][0-5])|[0-1]?[0-9]?[0-9])[.]){3}(
+([2]([0-4][0-9]|[5][0-5])|[0-1]?[0-9]?[0-9]))/;
# Open file to read lines
my $logfile = $ARGV[0];
my $linenum = 0;
open(LOGFILEHD, $logfile);
while( <LOGFILEHD>){
$Raw_Log = $_;
print "$Raw_Log\n";
$Raw_Log =~ /($re_ipv4).*($re_ipv4)/;
print "re1 -> $1\n";
print "re2 -> $2\n";
$linenum += 1;
}
close(LOGFILEHD);
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|