Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Parsing text file to CSV

by dwm042 (Priest)
on Aug 25, 2011 at 20:30 UTC ( [id://922446]=note: print w/replies, xml ) Need Help??


in reply to Parsing text file to CSV

This is a shot at trying to produce this suggested output

#!/usr/bin/perl use warnings; use strict; my $sep = "----------"; my $post_sep = 0; my $text_count = 1; while(<DATA>) { chomp; if ( $_ =~ /Important Text: (\d+)/ ) { $text_count = $1; } if ( $_ =~ /^$sep/ ) { $post_sep = 1; next; } if ( $post_sep ) { my @field = split " ", $_; printf "%d,%s,%s,%s,%s,%s,%s\n", $text_count,$field[0],$field[1],$field[2],$field[3],$field[4], +$field[5]; } } __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 looks like:

C:\Code>perl report_parse.pl 1,TEST,TT,TT00,TT00.1,NO,xxxx 1,TEST,TT,TT00,**TT00.2,YES,XXXXXX 1,TEST,TT,TT00,**TT00.3,YES,XXX 1,TEST,TT,TT01,TT01.1,NO,XXXXXXXXXXX 1,TEST,TT,**TT02,TT02.1,YES,XXXXX C:\Code>

Replies are listed 'Best First'.
Re^2: Parsing text file to CSV
by apok69 (Initiate) on Aug 25, 2011 at 22:49 UTC
    Thanks I'm going to try both and see what happens.

Log In?
Username:
Password:

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

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

    No recent polls found