Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: Extract Data Between Lines

by Athanasius (Abbot)
on Apr 04, 2014 at 02:45 UTC ( #1081061=note: print w/ replies, xml ) Need Help??


in reply to Extract Data Between Lines

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,


Comment on Re: Extract Data Between Lines
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (15)
As of 2015-07-31 20:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (281 votes), past polls