[thelist] Grep Question - match multiple lines but not greedy
Jay Blanchard
jay.blanchard at niicommunications.com
Fri May 6 14:07:20 CDT 2005
[snip]
I know enough RegEx to pull out the line I need using:
Subtotal[ ]+= \$([0-9]+\.00)
but I need to pull out the subtotals for a particular day so I need
something that will match line 1-30 like:
Date: May 5, 2005\r[\S\s]Subtotal[ ]+= \$([0-9]+\.00)
I can match line 1 and line 30 separately but I don't know how to match
the stuff in between without being greedy and matching the whole file.
I'd like to say, "Find a block of text where the first line is the
date, followed by some text I don't care about and the last line is the
Subtotal with the price that I do care about. Or to put it another way:
[/snip]
GREP might not be strong enough here, so you'll probably want to use
AWK. You may have to manipulate your file a little by making each e-amil
1 line in which you can get substrings....example follows (long, from an
existing script so you'll have to change)
#!/bin/sh
cat $1 | awk '
{
#common items
blank = ""
RecordID = substr($0, 1, 6)
RecordIDSuffix = substr($0, 7, 2)
SuffixRecordInd = substr($0, 9, 1)
ACNA = substr($0, 10, 5)
BillDate = convertDate(substr($0, 15, 8))
BillingNumber = substr($0, 23, 10)
CustomerCode = substr($0, 33, 3)
PackSequence = substr($0, 36, 4)
RecordSequence = substr($0, 40, 9)
ReservedEC = substr($0, 49, 13)
if (RecordID == "100505" && RecordIDSuffix == "00"){
#10-05-05-00 items
InvoiceNumber = substr($0, 62, 15)
Reserved = substr($0, 77, 60)
WebAddress = substr($0, 137, 45)
SvcCtrOrderInquiryNumber = substr($0, 182, 10)
SvcCtrPaymentInquiryNumber = substr($0, 192, 10)
SvcCtrContactNumber = convertPhone(substr($0, 202, 10))
SvcCtrOfficeCode = substr($0, 212, 4)
Reserved2 = substr($0,216, 10)
#create a file with the records delimited by commas, save to file named
for data table
print
blank","RecordID","RecordIDSuffix","SuffixRecordInd","ACNA","BillDate","
BillingNumber","CustomerCode","PackSequence","RecordSequence","ReservedE
C","InvoiceNumber","Reserved","WebAddress","SvcCtrOrderInquiryNumber","S
vcCtrPaymentInquiryNumber","SvcCtrContactNumber","SvcCtrOfficeCode","Res
erved2 > "tblBillFaceHeading00.tmp"
}
}'
More information about the thelist
mailing list