Extract range of lines from a text file
- From: Amer Neely <softouch@xxxxxxxxxxxxxx>
- Date: Sat, 08 Apr 2006 23:20:40 -0400
This is driving me nuts.
I'm walking through a mailbox file, and want to pull out specific lines from each message. The body of each message is in a similar format, having been generated by a script.
I'm doing OK except for one particular block of lines, the customer address data. There is a blank line before and after this block. Example:
Transaction Time: 18:45:55
Amer Neely
POB 1481 Station Main
North Bay ON
P1B 8K7
CANADA
123-456-7890
I've managed to get the 5 lines into a string using this code:
while <IN>
{
# bunch of other comparisons deleted
if (/^Transaction Time:/ ... /^\d\d\d-\d\d\d-\d\d\d\d$/)
{
$CustData = $_;
$CustData =~ s/^Transaction Time:.+//; # lose the beginning pattern
$CustData =~ s/^\d\d\d-\d\d\d-\d\d\d\d$//; # lose the ending pattern
next if ($CustData =~ m/^$/); # skip the blank lines
$CustData =~ s/\n//g; # get rid of blank lines. don't think this working
print "\t$CustData\n";
}
}
close IN;
print "\nAll done.\n";
The problem seems to be that $CustData holds all 5 lines. I need to break out each of the lines into a separate string variable so as to populate a database field. This is what has me stumped. Sure would appreciate some light on this.
--
Amer Neely
.
- Follow-Ups:
- Re: Extract range of lines from a text file
- From: Tad McClellan
- Re: Extract range of lines from a text file
- From: Dr.Ruud
- Re: Extract range of lines from a text file
- From: Amer Neely
- Re: Extract range of lines from a text file
- From: MSG
- Re: Extract range of lines from a text file
- From: Xicheng Jia
- Re: Extract range of lines from a text file
- From: Xicheng Jia
- Re: Extract range of lines from a text file
- Prev by Date: FAQ 4.7 How do I multiply matrices?
- Next by Date: Walking a tree and extracting info... Problems
- Previous by thread: FAQ 4.7 How do I multiply matrices?
- Next by thread: Re: Extract range of lines from a text file
- Index(es):
Relevant Pages
|