[thelist] Grep Question - match multiple lines but not greedy

Erik Heerlein erik at erikheerlein.com
Fri May 6 12:11:34 CDT 2005


I have a bunch of order confirmation emails in one text file that I 
need to pull out the Subtotal for each order(line 30). Below is a 
sample of one of the emails with line numbers.

1   Date: May 5, 2005
3   Order Number: 2309
4
5   Billing Address
6   ==========================================================
7   First Last name
8     street address
9     city state zip
10    email
11    phone
12
13  Shipping Address
14  ==========================================================
15  First Last name
16    street address
17    city state zip
18    email
19    phone
20
21    SHIPPING METHOD:  Priority - $7.85
22
23
24  Name of Item                  Quantity   Price      Total
25  ---------------------------------------------------------
26  stuff                             1     $20.00     $20.00
27
28
29  ==========================================================
30  Subtotal    = $20.00
31  Tax         = $0.00
32  Shipping    = $7.85
33  Total       = $27.85

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:

[the date]
[a bunch of lines]
[the Subtotal line (save the price)]



- Erik Heerlein



More information about the thelist mailing list