Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: Splitting a file into records

by Kenosis (Priest)
on May 03, 2013 at 16:23 UTC ( #1031925=note: print w/ replies, xml ) Need Help??


in reply to Splitting a file into records

I second LanX's suggestion (++) of using Perl's record separator ($/), but would initialize a local copy of it to 'STORE':

use strict; use warnings; local $/ = 'STORE'; my $count = 1; while (<DATA>) { chomp; if (/MONITORING/) { s/^\s+//; s/\s+$//; print "First two lines:\n$/ $_\n\n"; } elsif (/\S/) { print "\n\nRecord " . $count++ . ":\n$/ $_"; } } __DATA__ STORE MONITORING REPORT as of 13-05-02 10:05:07 Scanning for FTFIMS STORE002 -rwxr-xr-- 1 admins store 59025 Apr 11 2012 eft100.cbr 16295 58 -rwxr-xr-- 1 admins store 61143 Nov 15 15:47 chk075.cbr 33334 60 -rwxr-xr-- 1 admins store 420952 Sep 6 2012 test-encrypt 63327 412 -rwxr-xr-- 1 admins store 427068 Sep 6 2012 eft115-20 36184 418 -rwxr-xr-- 1 admins store 460694 Apr 3 06:15 eft6un 07640 450 -rwxrwxrwx 1 admins store 481069 Oct 4 2012 hostsocgw 46087 470 -rwxrwxrwx 1 admins store 503666 Feb 13 09:10 stratgw 22452 492 -rwxr-xr-- 1 admins store 14318 Nov 1 2010 unityrep 50196 14 STORE006 -rwxr-xr-- 1 admins store 59025 Apr 11 2012 eft100.cbr 16295 58 -rwxr-xr-- 1 admins store 61143 Nov 15 15:47 chk075.cbr 33334 60 -rwxr-xr-- 1 admins store 420952 Sep 6 2012 test-encrypt 63327 412 -rwxr-xr-- 1 admins store 427068 Sep 6 2012 eft115-20 36184 418 -rwxr-xr-- 1 admins store 460694 Apr 3 06:15 eft6un 07640 450 -rwxrwxrwx 1 admins store 481069 Oct 4 2012 hostsocgw 46087 470 -rwxrwxrwx 1 admins store 503666 Feb 13 09:10 stratgw 22452 492 -rwxr-xr-- 1 admins store 14318 Nov 1 2010 unityrep 50196 14

Output:

First two lines: STORE MONITORING REPORT as of 13-05-02 10:05:07 Scanning for FTFIMS Record 1: STORE 002 -rwxr-xr-- 1 admins store 59025 Apr 11 2012 eft100.cbr 16295 58 -rwxr-xr-- 1 admins store 61143 Nov 15 15:47 chk075.cbr 33334 60 -rwxr-xr-- 1 admins store 420952 Sep 6 2012 test-encrypt 63327 412 -rwxr-xr-- 1 admins store 427068 Sep 6 2012 eft115-20 36184 418 -rwxr-xr-- 1 admins store 460694 Apr 3 06:15 eft6un 07640 450 -rwxrwxrwx 1 admins store 481069 Oct 4 2012 hostsocgw 46087 470 -rwxrwxrwx 1 admins store 503666 Feb 13 09:10 stratgw 22452 492 -rwxr-xr-- 1 admins store 14318 Nov 1 2010 unityrep 50196 14 Record 2: STORE 006 -rwxr-xr-- 1 admins store 59025 Apr 11 2012 eft100.cbr 16295 58 -rwxr-xr-- 1 admins store 61143 Nov 15 15:47 chk075.cbr 33334 60 -rwxr-xr-- 1 admins store 420952 Sep 6 2012 test-encrypt 63327 412 -rwxr-xr-- 1 admins store 427068 Sep 6 2012 eft115-20 36184 418 -rwxr-xr-- 1 admins store 460694 Apr 3 06:15 eft6un 07640 450 -rwxrwxrwx 1 admins store 481069 Oct 4 2012 hostsocgw 46087 470 -rwxrwxrwx 1 admins store 503666 Feb 13 09:10 stratgw 22452 492 -rwxr-xr-- 1 admins store 14318 Nov 1 2010 unityrep 50196 14

Hope this helps!


Comment on Re: Splitting a file into records
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (8)
As of 2015-07-06 15:34 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 (77 votes), past polls