Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Multiple Line Regex Not Working

by kcott (Bishop)
on Nov 16, 2018 at 07:12 UTC ( #1225893=note: print w/replies, xml ) Need Help??


in reply to Multiple Line Regex Not Working

G'day ImJustAFriend,

Instead of reading one line at a time, you could read one chunk at a time by setting $/ (see perlvar: $/).

Here's a quick-and-dirty example script to demonstrate the technique. I pared down your posted data substantially; duplicated it; then labelled with "CHUNK 1" and "CHUNK 2".

#!/usr/bin/env perl use strict; use warnings; { local $/ = "\nMessage Id"; while (<DATA>) { chomp; /^message=(.*)\z/ms && print "$1\n"; } } __DATA__ <13>Nov 15 21:26:00 OamCOMM[365626]: TIMESTAMP=Thu Nov 15 21:26:00 2018 ... Severity=Inform message={username:xxxxxxx... causeDISTINGUISH_NAME=... ... CHUNK 1 ... label=x } Message Id=xxxxxxxx <13>Nov 15 21:26:00 OamCOMM[365626]: TIMESTAMP=Thu Nov 15 21:26:00 2018 ... Severity=Inform message={username:xxxxxxx... causeDISTINGUISH_NAME=... ... CHUNK 2 ... label=x } Message Id=xxxxxxxx

Output:

{username:xxxxxxx... causeDISTINGUISH_NAME=... ... CHUNK 1 ... label=x } {username:xxxxxxx... causeDISTINGUISH_NAME=... ... CHUNK 2 ... label=x }

— Ken

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2021-05-15 03:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Perl 7 will be out ...





    Results (150 votes). Check out past polls.

    Notices?