Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Search file for certain lines

by Jalcock501 (Sexton)
on Sep 23, 2013 at 10:08 UTC ( #1055262=note: print w/ replies, xml ) Need Help??


in reply to Search file for certain lines

Hey Guys Sorry it's so ambiguous. Here is some example data.

h132BIK2 u3*** TEST DATA *** u3*** COMMENT AREA FOR TEST DATA *** j1000010017 6790194100109201301092013Test Data N PW09-3PY248 +018BIK20 k10 2R 1 0045.1011N01010215.820012.220006.0000000 0250M 1I +nsured Only NYY01N00000.00N00000.00Y00000. +00 000215.82000012.22000006.00 q0215.820215.820215.820215.820215.820000000000000000000002500250025002 +500250YY00000 01000215.82000215.82000215.82000215.82000215.82 l02001 0400000000 +0000000000000000000000000000000000000000 a000.00000.00000.0000 E99HEADER|004|001| E99INSSCH|248| E99POLCOM|3||CAP01|66|3301R7435459||||| E99INSFAC2|MSRA01_1||||||"LNI10708"| G3301R7435459:LNI10708 yIIDD0043.160019.0110018.9909M0000.000010.000233.08N0017.270023.500000 +43.16000019.01000018.99000000.00000010.00000233.08000017.27 h216BIK0 u3*** TEST DATA *** u3*** COMMENT AREA FOR TEST DATA *** pMU76 Nov 2010 A B C D E F G H + I J L + + 0000000000 j1000010017 6790194100109201301092013Test Data M PW09-3PY248 +005BIK00 k10 2R 1 0045.1011N01010217.190012.290006.0000000 0250M 1I +nsured Only NYY01N00000.00N00000.00Y00000. +00 000217.19000012.29000006.00 q0217.190217.190217.190217.190217.190000000000000000000002500250025002 +500250YY00000 01000217.19000217.19000217.19000217.19000217.19 l02001 0400000000 +0000000000000000000000000000000000000000 a000.00000.00000.0000 E99HEADER|004|001| E99INSSCH|248| E99POLCOM|3||CAP01|66|3301R7435459||||| E99INSFAC2|MSRA01_1||||||"LNI10708"| G3301R7435459:LNI10708 yIIDD0043.440019.1410019.1109M0000.000010.000234.57N0017.380023.500000 +43.44000019.14000019.11000000.00000010.00000234.57000017.38 h217BIK1 u3*** TEST DATA *** u3*** COMMENT AREA FOR TEST DATA *** pMU76 Nov 2010 A B C D E F G H + I J L + 0000000000 j1000010017 6790194100109201301092013Test Data L PW09-3PY248 +006BIK10 k10 2R 1 0045.1011N01010222.940012.620006.0000000 0250M 1I +nsured Only NYY01N00000.00N00000.00Y00000. +00 000222.94000012.62000006.00 q0222.940222.940222.940222.940222.940000000000000000000002500250025002 +500250YY00000 01000222.94000222.94000222.94000222.94000222.94 l02001 0400000000 +0000000000000000000000000000000000000000 a000.00000.00000.0000 E99HEADER|004|001| E99INSSCH|248| E99POLCOM|3||CAP01|66|3301R7435459||||| E99INSFAC2|MSRA01_1||||||"LNI10708"| G3301R7435459:LNI10708 yIIDD0044.590019.6110019.6209M0000.000010.000240.78N0017.840023.500000 +44.59000019.61000019.62000000.00000010.00000240.78000017.84
This is a small portion but it should give you the idea. As you can see there is some other information between lines that I need. To clarify further I do not need the lines beginning with h, they are just markers to search between.


Comment on Re: Search file for certain lines
Download Code
Re^2: Search file for certain lines
by wjw (Curate) on Sep 23, 2013 at 11:00 UTC
    ahhh... So there are not h-starts and h-stops. h(lower case) simply indicates the beginning of a record. My approach would be to find h line and use is as the key in a hash, then iterate until finding each of the subsequent j,E,G lines and adding them as an array under the key(HoA). When you find another h-line, you make a new key and wash,rinse,repeat until end of data. You end up with a structure which is pretty easy to continue to manipulate and do further clean up on if you want to.

    I am sure there are a bunch of other ways to do this, many better. But what I like about this approach is that it uses well documented data structures which are simple to manipulate. Good luck! Should be fun... :-)

    • ...the majority is always wrong, and always the last to know about it...
    • The Spice must flow...
    • ..by my will, and by will alone.. I set my mind in motion
Re^2: Search file for certain lines
by mtmcc (Hermit) on Sep 23, 2013 at 11:01 UTC
    What output do you expect to get from that data?
Re^2: Search file for certain lines
by pvaldes (Chaplain) on Sep 23, 2013 at 11:49 UTC

    mmmh... change the input field separator $/?

    or slurp the entire file and split by ^h?

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (9)
As of 2014-12-18 13:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (51 votes), past polls