I'm sure you'll be able to do what you need with Perl. Go out and get davorg's book Data Munging with Perl; it describes what you need to know to do this sort of thing. You can pick up the book on-line as a PDF for USD 18.50 from the publisher, but the printed copy is nice to have.

You will still need to think about how the records in your text file can be isolated from one another. For us to help you in this forum, we'd need to know whether the information after the three-digit record type is also significant, i.e. whether it also needs to be divided up into fields. From what you have told us already, you could use a function called unpack to do this:

#!/usr/bin/perl use strict; use warnings; my $template = 'A3A*'; # for unpack. it says you have some # ASCII data of a fixed length of 3, # and some more ASCII data until the # end of the record (record means 'li +ne' here) while (<DATA>) { my ($recordtype,$datastring) = unpack($template,$_); print "Record type: $recordtype\n$datastring\n\n" unless $recordtype + eq ''; } __DATA__ 090071905090405611071905001029842000281253P0223P0504011 80017 090071905090405611071905001029842000291253P0223P0504011 80007 03007190519912660000739900000026500 03007190519912660000839900000011500 040071905453901800xxxxxx x xxxxxxxx M4000 040071905453901806xxxxxx xxxxxxxx F4131 05007190545393434503187100 05007190545393963405187100 06007190545337000380199516129001399002650 06007190545337182980240356129999399013784 OUTPUT: Record type: 090 071905090405611071905001029842000281253P0223P0504011 80017 Record type: 090 071905090405611071905001029842000291253P0223P0504011 80007 Record type: 030 07190519912660000739900000026500 Record type: 030 07190519912660000839900000011500 Record type: 040 071905453901800xxxxxx x xxxxxxxx M4000 Record type: 040 071905453901806xxxxxx xxxxxxxx F4131 Record type: 050 07190545393434503187100 Record type: 050 07190545393963405187100 Record type: 060 07190545337000380199516129001399002650 Record type: 060 07190545337182980240356129999399013784

--
Allolex


In reply to Re: ascii manipulation in perl by allolex
in thread ascii manipulation in perl by brkstr

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.