Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

comment on

( [id://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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2024-04-18 06:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found