Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

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".

In reply to Re: regex optional word match by brx
in thread Parsind data in xlsx by Rahul Gupta

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others rifling through the Monastery: (6)
    As of 2018-07-16 03:18 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (330 votes). Check out past polls.

      Notices?