Hello namelkcip, and welcome to the Monastery!

Here is one approach:

#! perl use strict; use warnings; my $record; while (<DATA>) { if (/^object network/) # new record { process_record($record) if $record; $record = $_; } else { $record .= $_; } } process_record($record) if $record; sub process_record { my ($record) = @_; print $record, '-' x 36, "\n"; } __DATA__ object network Microsoft.Lync.Host.3 host 138.108.25.111 description Help Desk Ticket #476739 object network Microsoft.Lync.Host.4 host 138.108.25.112 description Help Desk Ticket #476739 object network Microsoft.Lync.Host.5 host 138.108.25.113 description Help Desk Ticket #476739 object network Microsoft.Lync.Host.6

Output:

12:41 >perl 891_SoPW.pl object network Microsoft.Lync.Host.3 host 138.108.25.111 description Help Desk Ticket #476739 ------------------------------------ object network Microsoft.Lync.Host.4 host 138.108.25.112 description Help Desk Ticket #476739 ------------------------------------ object network Microsoft.Lync.Host.5 host 138.108.25.113 description Help Desk Ticket #476739 ------------------------------------ object network Microsoft.Lync.Host.6 ------------------------------------ 12:41 >

This handles records of variable line lengths, while still only reading the data line-by-line.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,


In reply to Re: Extract Data Between Lines by Athanasius
in thread Extract Data Between Lines by namelkcip

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.