Hi,

I am trying to parse a delimited file and based on certain
logic creating separate files.
Here's content of a sample file with '^' as the separator -

1^InformationCompanyConsumerUpdateFile^4457^1/07/2002^14:35
2^1^john.doe@imail.com^1234^20020102
3^1^^Johnathon^Doe^^8^
4^1^1^123 Happy Trail Drive^^Tuscon^AZ^44587^1487
8^1^BU1534567^12345^01119
2^2^Fanklin.Roosevelt@whitehouse.com^1234^20020105
3^2^^Franklin^Roosevelt^^8^
4^2^1^55 Congress Drive^^Washington^DC^11265^
8^2^BU1234567^12345^01119
2^3^lincoln@log.com^1234^20020101
4^3^1^99 Honest ^^Chicago^IL^58302^
8^3^BU222234^ 01595^01119|011124
8^3^BU222234^ 02516^Y
8^3^BU222234^ 01616^2

The second value like 1, 2, 3 ... are the unique ids for
the records of a particular individual.
The first column value is the record type.
For example 1 is for the header information, 2 for the email
information etc., 3 is for the individual's first, middle,
last name etc., 8 is for the questionaire answers.
. Based on the unique id (key) as mentioned above
I need to create 3 separate pipe delimited files like as below -

Header file (for first column value of '1') -

InformationCompanyConsumerUpdateFile|4457|1/07/2002|14:35

Data file (for first column values of '3,4 and 2' in sequence)-

1||Johnathon|Doe||8|123 Happy Trail Drive||Tuscon|AZ|44587|1487|john.doe@imail.com|1234|20020102

Questionaire file (for first column value of '8') -

1|BU1534567|12345|01119

I hope I have stated my problem clearly.
Would appreciate if I could find the best possible solution
for this problem.<pr> Thanks


In reply to Parsing a file and splitting into multiple files by tariqahsan

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.