This script concatenates multi-line messages, printing them as it goes.

use strict; use warnings; my $buffer = q(); while(<DATA>) { chomp; if(/KB[0-9]/) { $buffer .= $_; } else { print "$buffer\n" if $buffer; $buffer = $_; } } print "$buffer\n"; __DATA__ "Information","17","4/13/2006 12:54:25 PM","Windows Update Agent","ISA +","Installation","N/A","Installation Ready: The following updates are + downloaded and ready for installation. To install the updates, an ad +ministrator should log on to this computer and Windows will prompt wi +th further instructions: - Security Update for Windows Server 2003 (KB911562) - Windows Malicious Software Removal Tool - April 2006 (KB890830) - Cumulative Security Update for Internet Explorer for Windows Server +2003 (KB912812) - Security Update for Windows Server 2003 (KB908531) - Cumulative Security Update for Outlook Express for Windows Server 20 +03 (KB911567)" "Information","17","4/13/2006 12:54:19 PM","Windows Update Agent","ISA +","Installation","N/A","Installation Ready: The following updates are + downloaded and ready for installation. To install the updates, an ad +ministrator should log on to this computer and Windows will prompt wi +th further instructions: - Security Update for Windows Server 2003 (KB911562) - Windows Malicious Software Removal Tool - April 2006 (KB890830) - Cumulative Security Update for Internet Explorer for Windows Server +2003 (KB912812) - Security Update for Windows Server 2003 (KB908531)"

I hope it is of use.

Cheers,

JohnGG

Update:

I looked at this again and wondered how it was printing the last log message when I had forgotten to do a final print statement after the while loop. It was working because there was a blank line at the end of the __DATA__ file (I nearly said Data Division thus revealing a murky COBOL past).

Code now corrected.


In reply to Re: Problem with matching multiple lines by johngg
in thread Problem with matching multiple lines by jeiku

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, details, 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, summary, 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.