I have a text file that I need to parse into a comma delimited file with perl installed on an XP PC. PERL is working, I have other perl programs running so I can handle that part..
But I dont' know how to parse this text. The test represents records, that may or may not have all the data and may span multiple lines.
- the "pr" field starts each "record"
- the fields in each record can be missing or there
- long records wrap with a return, but they do not wrap within the text of a data item AFAIK
- the fields are always in the same order when there.
I suppose I need to match starting at one point up to another match. I'm no perl guru by any stretch and I don't know how to do what I hope is straightforward.
2 sample records:
pr 50 stat SPR
pr 51 stat WKG cq A9
ckid xxx 123-1234 lp stat WKG au SAFAL bp/clr 12 svc-typ NONE
tea X 9 MAIN ST type FIXED co side capr AHJX4318A:192
dist tea X 10 MAIN ST type FIXED addr: 123 SIDE ROAD DR
com MYPLACE state AK serv tea X 11 MAIN ST type FIXED
The things in lower case are the fields. One "record's" fields are:
pr
stat
ckid
lp stat
au
bp/clr
svc-typ
As you can see the "data" items can have spaces. And the record names can have spaces and slashes e.g. (bp/clr, lp stat)
It's over my head on how to chop this out. My goal is to get the data only into a spreadsheet. If I can parse it into CSV data I'd be in business.
Can anyone help?
Thanks! Scott
Start Free Trial