update: input data changed by OP (backets added) - consider kcott's answer : Re: regex optional word match
-*-*-*-*-
If you really-really want to use a big regex, see:
$line =~ m/^REMOTE\s+(.*?)\s+(\S+)\s+(\S+)\s+(\S+)\s+(\S+)\s+(.*?)\s+(
+.*?)sec\s+(.*)MBytes\s+(.*)Mbits\/sec(.*)/s;
print "{$10}"; #$10 should contain at least "\n" except if you 'ch
+omp $line'
This regex become very complex if 'MBytes' could be 'Bytes', etc.
But here is another way with split (because lines seem to be well formated with "space-separator").
#!perl
use strict;
use warnings;
while (my $line = <DATA>) {
chomp $line;
my @parts = split /\s+/,$line;
#REMOTE Mon Jul 16 21:49:33 2012 @@ ueh1 TNT 20490 1916 0.0- 1.0 sec 0
+.33 MBytes 2.74 Mbits/sec 6.056 ms 0/ 233 (0%)
#0 1 2 3 4 5 6 7 8 9 10 11 12 13 1
+4 15 16 17 18 19 20 21 22
next if $parts[0] ne 'REMOTE';
print "IN: $line\n";
print "\tOUT: ",join " ",@parts[1..5,8,12,13];
print " ", join " ",@parts[18,19] if $#parts>=19;
print "\n";
}
__DATA__
REMOTE Mon Jul 16 21:49:33 2012 @@ ueh1 TNT 20490 1916 0.0- 1.0 sec 0.
+33 MBytes 2.74 Mbits/sec 6.056 ms 0/ 233 (0%)
REMOTE Mon Jul 16 21:49:34 2012 @@ pdn1 SSH 20499 3 1.0- 2.0 sec 0.34
+MBytes 2.86 Mbits/sec
LOCAL Mon Jul 16 21:49:34 2012 @@ nada
Output:
IN: REMOTE Mon Jul 16 21:49:33 2012 @@ ueh1 TNT 20490 1916 0.0- 1.0 se
+c 0.33 MBytes 2.74 Mbits/sec 6.056 ms 0/ 233 (0%)
OUT: Mon Jul 16 21:49:33 2012 TNT 1.0 sec 6.056 ms
IN: REMOTE Mon Jul 16 21:49:34 2012 @@ pdn1 SSH 20499 3 1.0- 2.0 sec 0
+.34 MBytes 2.86 Mbits/sec
OUT: Mon Jul 16 21:49:34 2012 SSH 2.0 sec
update: /s modifier in regex
English is not my mother tongue.
Les tongues de ma mère sont "made in France".
-
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.