Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Parsing text file to CSV

by dwm042 (Priest)
on Aug 25, 2011 at 20:30 UTC ( #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 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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://922446]
[choroba]: thank you
Discipulus or was mine?!?
[beech]: thank you, it sure is pretty "code", yup, thats what I call it my ...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (6)
As of 2017-02-28 07:58 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (398 votes). Check out past polls.