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

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Perl code can be remarkably compact if your requirements are loose (as they appear to be).

#!/usr/bin/perl use strict; my $important; while ( ( $_ = <DATA> ) !~ /^\-{10,}$/ ) { $important = $1 if /^Important Text: (\d+)$/i; } while ( <DATA> ) { print join ( ",", $important, split ( /\s+/ ) ) . "\n"; } __DATA__ Date 08/17/11 Report Page 1 Time 12:46 Important Text: 1 Misc Text: All Misc Text: Sec ** Indicates APPTEXT PLINE SCODE PCODE FID SEC unsec fcs ---------------------------------------------------------------------- +--------------------------- TEST TT TT00 TT00.1 NO xxxx TTD TEST TT TT00 **TT00.2 YES XXXXXX TEST TT TT00 **TT00.3 YES XXX TEST TT TT01 TT01.1 NO XXXXXXXXXXX TT TEST TT **TT02 TT02.1 YES XXXXX
Output:
1,TEST,TT,TT00,TT00.1,NO,xxxx,TTD 1,TEST,TT,TT00,**TT00.2,YES,XXXXXX 1,TEST,TT,TT00,**TT00.3,YES,XXX 1,TEST,TT,TT01,TT01.1,NO,XXXXXXXXXXX,TT 1,TEST,TT,**TT02,TT02.1,YES,XXXXX

In reply to Re: Parsing text file to CSV by thewebsi
in thread Parsing text file to CSV by apok69

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others about the Monastery: (3)
As of 2024-04-26 00:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found