Grep range of lines to print a line number on match

Hi Guru's,
I am trying to grep a range of line numbers (based on match) and then look for another match which starts with a special character '$' and print the line number. I have the below code but it is actually printing the line number counting starting from the first line of the range i am looking in.

I actually want it to print the line number of this match (starting with $ symbol) with a range of lines from a file.
an example match could be $x,xxx.xx but not always the same in the length.

string_contd_nxt_page=`grep -n "continued on next page" sample.txt|cut -d : -f1`
eos_page_1=`echo $string_contd_nxt_page|cut -d " " -f1`
eos_page_2=`echo $string_contd_nxt_page|cut -d " " -f3`
sos_page_2=`echo $string_prch_n_adjsmnts|cut -d " " -f2`
string_Fees=`grep -n Fees$ sample.txt|cut -d : -f1`
Eof_String_Fees=`echo $string_Fees|cut -d " " -f1|awk '{print $1-1}'`

END_Of_Statement=`sed -n "$sos_page_2,$Eof_String_Fees"p sample.txt|grep -Fn '$'|cut -d : -f1`

It would be better if can paste a sample input and expected output.

--ahamed

1 Like

Sure here is the sample page X of many pages but this is where the match i am interested in....

**************************** Page 3 ****************************








                                    xxxx xxxx xxxx  xxxx
                                    June 9 - July 10, 2012
                                    Page 3 of 6

       Transactions   continued

       Transaction Posting                                                                Reference    Account
       Date       Date           Description                                              Number       Number                 Amount            Total

                                 Purchases and Adjustments
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   7907         2788                     1.25
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   6291         2788                   21.28
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   0917         2788                     8.43
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   5704         2788                     1.25
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   4753         2788                   42.83
                 
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   8560         2788                  120.82
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   5185         2788                   26.42
                 ......................................
                 ......................................
                 ......................................
                 ......................................
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   5393         2788                   14.13
       MM/DD      MM/DD          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   3611         2788                   14.92
                                 

                                                                                  THIS IS THE MATCH I NEED THE LINE NUMBER FOR ============>  $1,350.74
**************************** Page 4 ****************************




       Transactions   continued

       Transaction Posting                                                                Reference    Account

You need to give more details on the expected output.
So all you want is the line number for $1,350.74?

--ahamed

yes, all i want is the line number for $1,350.74, but within a range of line numbers specified.

Try this

start=100
end=120
awk '/'$start'/,/'$end'/{if(match($0,/\$/)){print NR}}' infile
awk 'NR>=start && NR<=end{if(match($0,/\$/)){print NR;exit}}' start=100 end=120 infile
sed -n '/'$start'/,/'$end'/{/\$/=}' infile

where start and end specified the range of line numbers.
Using NR or FNR for print depends on if you have one file or multiple files.

--ahamed

1 Like

For the data you have supplied, the following does what you want:

awk -F'$' 'NF > 1{print NR}' sample.txt

If you are using a Solaris/SunOS system, use /usr/xpg4/bin/awk , /usr/xpg6/bin/awk , or nawk instead of awk .

1 Like

If you want to print line number and the matching pattern: $x,xxx.xx

awk '/\$/{ match ($0, /\$[ ]*[0-9,]*[.][0-9]*/); print NR, substr($0, RSTART, RLENGTH) }' file.txt
1 Like
sed -n '
  line1,line2{
    /pattern/{
      #
      q
     }
   }
 ' file
1 Like

All,

Thanks for all your replies.....

Sorry for not being descriptive initially, let me try this time....

Basically, I am trying to print this page (besides many pages i am able to) with all the transactions listed till the line total amount in "$" amount. A sample data is posted above.

For this i am defining the start of this specific page based on the match as follows....

Page(n)_Start = Line number of last occurrence of the match "Purchases and Adjustments" in the whole input file.
Page(n)_End = Line number of Fixed string match "Fees" - 1 in the input file  

(This should ideally print lines till the total "$" amount I am interested in.)

I am able to this fine but sometimes (different input file) there is some junk data between the "$" amount and the "Page(n)_End" which I don't want to be displayed and hence I am trying to see if there is way to print the line number of this match "$" amount between "Page(n)_Start" and "Page(n)_End" and either make that line number the Actual/New "Page(n)_End" or print only till that "$" amount line.

Details of the Match "$" amount:-
It starts with a "$" character and rest are always numbers but it could have any numbers of characters.
This is just an example: -

$ x,xxx.xx

The reason I am trying to search for this match between specific lines is because such matches are in multiples in the input file.

Please let me know if need more details....

Thanks again

No, a sample is not posted above. All that you have shown us is part of a page 3 and part of a page 4 of a sample of a single transaction. You have not shown us anything that contains "_Start", "_End", "Purchases and Adjustments", or any other string you say you're looking for (except for the "$").

It appears that you are asking us to help you produce an extremely inefficient way to separate statements into separate files or to discard unwanted text between statements and just print the statements from a file (or from multiple files) containing multiple statements. You say that only numbers follow the "$", but that is not true ("," and "." are not numbers). And why do we care? The only $ in the entire sample you have shown us is $ you want to find. So, my script gave you the line numbers of all lines containing a $. If there are multiple statements (or transactions) in your input file and you have set $start in your shell to be the 1st line of a transaction and you just want the line number of the 1st line after that that contains a $, try:

awk -F'$' -v low="$start" 'NF<2 || NR<low{next}{print NR; exit}' sample.txt

If you'd like us to help you create a script that will throw away everything between "transactions" or split "transactions" into separate files efficiently, then give us a real example and an accurate description of how to identfy the 1st and last lines of a "transaction", and then describe what you want to be done with the "transactions" found.

1 Like

Appreciate for your response... I am sure my approach is not efficient enough. I am a complete novice in scripting. I am just a beginner and practicing few things to pick up. For this one I am basically playing around with my own monthly bank statements (text file) to filter out unwanted data and put them in to another text file and then import it in to excel columns filtering out by type of transactions (different categories (columns) like Household, Health , travel etc., etc.,...

I am attaching a complete sample text file.

There are mainly three sections I am interested in and want these sections to be separated out in to another file.

  1. Payments and Other Credits :- (Top section - Lines 53-58 in the sample data example)
  2. Purchases and Adjustments :- (Middle section - Lines60-61, 110-167 in the sample data example)
  3. Fees :frowning: Bottom section - Lines 178-196 in the sample data example)

Hope this helps. Please let me know if need more information...

Thank You

Yeah, cool, text mining. You have to disassemble your internal personal mental process as with your eyes you find the data you want and ignore the data you do not want, so you can code a robust and effective tactic for mining out the hunks you want.

To make parsing easier, sometimes it is good to preprocess out blank lines, long white spaces, boilerplate text, etc., so you have a simpler problem left. Sometimes multiple passes are good, getting all the common bits and then going back for the detail lines, pasting the common bits on their details, resuting in lines like rows of a denormalized table in a database.

If your take your text, paste it into an HTML formatted email, you can mark it up, copy it and paste the html with markup into the forum directly, so we can see what you want to mine.

Output format desired is good to know, too.

1 Like

Thank You, I am posting the data as instructed..

**************************** Page 1 ****************************
   
   
   
   
   
   
   
   
                                  FIRSTNAME LASTNAME
                                  Account Number: xxxx xxxx xxxx  xxxx
                                  June 9 - July 10, 2012 
   
      Account Information:
      www.xxxxxxxxxxxx.com         Payment   Information                                                   Account   Summary
   
      Mail billing inquiries to:   New Balance Total.....................................................................$1,123.69 Previous Balance........................$2,277.64
      Bank of Xxxxxxx              Current Payment Due ......................................................................$33.00 Payments and Other Credits........... - 2,536.16
      P.O. Box xxxxxx                                                                                      Purchases and Adjustments.............1,350.74
      XX Xxxx, XX xxxxx-xxxx
                                   Total Minimum Payment Due............................................................$33.00 Fees Charged.................................................31.47
      Mail payments to:            Payment Due Date..........................................................................8/7/12 Interest Charged...............................................0.00
      Bank of Xxxxxxx
      P.O. Box xxxxxx              Late Payment Warning:  If we do not receive your Total Minimum Payment by New Balance Total ........................$1,123.69
      Xxxxxx, XX xxxxx-xxxx        the date listed above, you may have to pay a late fee of up to  $35.00 .
   
      Customer Service:            Total Minimum Payment Warning:  If you make only the Total Minimum      Total Credit Line............................$5,000.00
      1.XXX.XXX.XXXX               Payment each period, you will pay more in interest and it will take you longer Total Credit Available.....................$3,876.31
                                   to pay off your balance. For example:                                   Cash Credit Line ..............................$500.00
      (1.XXX.XXX.XXXX TTY)                                                                                 Portion of Credit Available for Cash....$500.00
   
                                      If you make no        You will payoff       And you will end         Statement Closing Date ...................7/10/12
                                     additional charges      the balance      up paying an estimated       Days in Billing Cycle ..................................32
                                       using this card      shown  on this            total of
                                    and each month you    statement in about
                                            pay
   
                                        Only the Total          11 years             $2,471.20
   
                                      Minimum Payment
                                          $41.76              36 months              $1,503.36
                                                                                 (Savings = $967.84)
   
   
                                   If you would like information about credit counseling services, call
                                   1-XXX-XXX-XXXX.
   
   
         Transactions
   
         Transaction Posting                                                               Reference     Account
         Date       Date          Description                                              Number        Number                 Amount           Total
                                  Payments and Other Credits
                    06/18         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   2459          XXXX                 - 247.10
   
                    07/09         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   4383          XXXX                  - 12.06
         07/09      07/10         PAYMENT - ELECTRONIC                                     0050                             - 2,277.00
                                                                                                                                           - $2,536.16
   
                                  Purchases and Adjustments
         06/09      06/11         XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   7683          XXXX                    2.50
                                  continued on next page...
   
   
   
   
   
                      08   001123690000330000227700000426428597547XXXX
   
   
   
                     BANK OF XXXXXXX                                         Account Number:  XXXX XXXX XXXX  XXXX  
                     P.O. BOX XXXXXX
                     XXXXXX, XX XXXXX-XXXX
                                                                             New Balance Total...........................................................$1,123.69
                                                                             Total Minimum Payment Due...................................................33.00
                                                                                Payment Due Date  ...................................................08/07/12
   
   
                   FIRSTNAME LASTNAME                                             Enter payment amount   $
                                                                                                                             .
                   XXX STREET ADDRESS
                   STATE XX  XXXXX-XXXX 
                                                                                 Check here for a change of mailing address or phone numbers.
                                                                                 Please provide all corrections on the reverse side.
                                                                             Mail this coupon along with your check payable to: XXXX of Xxxxxxx
   
   
                                                     A524022250A                0887597547XXXXC
  **************************** Page 2 ****************************
  **************************** Page 3 ****************************
   
   
   
   
   
   
   
   
                                      XXXX XXXX XXXX  XXXX
                                      June 9 - July 10, 2012
                                      Page 3 of 6  
   
         Transactions   continued
   
         Transaction Posting                                                                Reference    Account
         Date       Date           Description                                              Number       Number                 Amount            Total
   
                                   Purchases and Adjustments
         06/09      06/11          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   7907         XXXX                     1.25
         06/09      06/11          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   6291         XXXX                   21.28
         06/09      06/11          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   0917         XXXX                     8.43
         06/12      06/13          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   5704         XXXX                     1.25
         06/12      06/13          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   4753         XXXX                   42.83
                                   ESH0RU69AA8
         06/14      06/16          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   8560         XXXX                  120.82
         06/15      06/16          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   5185         XXXX                   26.42
   
         06/16      06/18          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   4709         XXXX                   33.53
         06/16      06/18          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   1396         XXXX                     1.25
         06/16      06/18          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   1388         XXXX                     2.50
         06/16      06/18          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   1466         XXXX                   63.57
         06/16      06/18          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   8903         XXXX                  114.51
         06/17      06/18          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   7934         XXXX                     7.14
         06/18      06/19          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   7627         XXXX                     4.67
                                   762
         06/19      06/19          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   4738         XXXX                   48.73
                                   8220111103449627
         06/18      06/20          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   9884         XXXX                     1.90
         06/22      06/23          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   2647         XXXX                     5.76
                                   08515951181MVRYW000687675
         06/22      06/25          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   5841         XXXX                  101.74
         06/23      06/25          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   6295         XXXX                   21.41
   
         06/23      06/25          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   6295         XXXX                   31.12
         06/23      06/25          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   0648         XXXX                   11.94
         06/23      06/25          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   1999         XXXX                   64.07
                                   XXXX
         06/23      06/25          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   1967         XXXX                    34.66
                                   98201772CVI
         06/24      06/26          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   6354         XXXX                   56.31
         06/24      06/26          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   1248         XXXX                     2.12
         06/24      06/26          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   7511         XXXX                   40.11
         06/24      06/26          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   6708         XXXX                     2.50
         06/24      06/26          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   6732         XXXX                     2.50
         06/27      06/29          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   1955         XXXX                     1.25
         06/27      06/29          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   2029         XXXX                     1.25
         07/01      07/02          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   4282         XXXX                   53.72
         07/01      07/02          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   0914         XXXX                   19.99
   
                                   71674450194044186116
         07/03      07/05          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   0311         XXXX                   11.06
         07/03      07/05          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   5163         XXXX                   27.41
                                   08515951181MVRYW000809736
         07/04      07/05          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   0332         XXXX                     6.40
         07/04      07/05          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   0688         XXXX                   10.00
         07/04      07/06          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   3898         XXXX                  119.80
         07/04      07/06          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   3948         XXXX                   38.60
         07/06      07/07          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   0704         XXXX                   17.90
         07/06      07/09          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   9563         XXXX                   97.50
         07/07      07/09          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   4468         XXXX                   39.99
                                   08515951181MVRYW000761525
         07/08      07/09          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   5393         XXXX                   14.13
         07/08      07/09          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX                   3611         XXXX                   14.92
                                   08515951181MVRYW000665299
   
                                                                                                                                            $1,350.74
  **************************** Page 4 ****************************
   
   
   
   
         Transactions   continued
   
         Transaction Posting                                                                Reference    Account
         Date       Date           Description                                              Number       Number                 Amount            Total
   
                                   Fees
         07/07      07/07          LATE FEE FOR PAYMENT DUE 07/07                           3214                                22.00
         07/10      07/10          CREDIT PROTECTION PLUS XXX.XXX.XXXX                      500P                                  9.47
                                   TOTAL FEES FOR THIS PERIOD                                                                                  $31.47
   
                                   Interest Charged
   
         07/10      07/10          Interest Charged on Purchases                                                                  0.00
         07/10      07/10          Interest Charged on Balance Transfers                                                          0.00
         07/10      07/10          Interest Charged on Dir Dep&Chk CashAdv                                                        0.00
         07/10      07/10          Interest Charged on Bank Cash Advances                                                         0.00
                                   TOTAL INTEREST FOR THIS PERIOD                                                                               $0.00
   
   
                                                      2012 Totals Year-to-Date
   
                                    Total fees charged in 2012                              $122.93
   
                                    Total interest charged in 2012                             $0.00
   
   
   
         Interest  Charge  Calculation
         Your Annual Percentage Rate (APR) is the annual interest rate on your account.
   
                                                                     Annual    Promotional   Promotional  Promotional     Balance         Interest
                                                                   Percentage   Transaction    Offer ID    Rate End      Subject to     Charges by
                                                                      Rate         Type                      Date         Interest      Transaction
                                                                                                                            Rate           Type
   
                             Purchases                               20.99%V                                               $0.00          $0.00
                                    Promotional APR                   0.00%     PUR, WT     XXXX-XXXXX   09/10/2012                       $0.00
                             Balance Transfers                       20.99%V                                               $0.00          $0.00
                             Direct Deposit and Check Cash           24.99%V                                               $0.00          $0.00
                             Advances
                             Bank Cash Advances                      24.99%V                                               $0.00          $0.00
   
         APR Type Definitions: Promotional Transaction Types: PUR = Purchase, WT = Non-Bank Wire Transfer; Daily Interest Rate Type: V= Variable Rate (rate may vary)
   
   
   
   
   
         Rewards
                                                      BANKXXXXXCARD CASH REWARDS
                                                          10.70  BASE EARNED THIS MONTH
                                                           5.64  BONUS THIS MONTH
                                                            .00  REDEEMED
                                                         205.24  TOTAL AVAILABLE
                                                      VISIT xxxxxxxxxxx.COM/CASHREWARDS
   
   
         Of Special Interest
   
         Discover the convenience of paperless statements: enjoy easy organization of your account statements, review your statement and transactions sooner, and
         reduce your risk of mail fraud and identity theft - all while taking another step towards a greener lifestyle. Simply sign in to your online banking account at
         www.xxxxxxxxxxxx.com and click the green leaf �go paperless� icon to get started.
  **************************** Page 5 ****************************
   
   
      Enjoy a low 0%  promotional                                                                                                           1030
      APR through your statement
                                                FIRSTNAME LASTNAME                                                 Check not valid after 9/9/12
      Closing Date in May 2013 on
                                                STREET ADDRESS
      the enclosed checks when
                                                STATE XX  XXXXX-XXXX                                         DATE                             62-16
      used by September 9, 2012.                                                                                                               311
                                                                                                              Offer ID XXXX-XXXXX
      When your promotional offer               PAY TO THE
                                                ORDER OF                      V      O       I    D                              $
      expires, these balances will be
      charged a variable APR,
                                                                                                                                          DOLLARS
      currently 24.99%.
                                                               XXXCard Services, X.X.
                                                               XXXXXXXXXX, XXXXXXXX
      These checks can be a great
                                                FOR
      financial tool to help you pay
      down your balances faster. �
                                                     A031100160A08770194992865C1030
      Call  1-XXX-XXX-XXXX  or visit 
      www.XXXXXXXXXXXX.com  to                                                                                                             1031
      access your account.
                                                FIRSTNAME LASTNAME
                                                                                                              Check not valid after 9/9/12
                                                XXX STREET ADDRESS
                                                STATE XX  XXXXX-XXXX                                         DATE                             62-16
                                                                                                                                               311
                                                                                                              Offer ID XXXX-XXXXX
                                                PAY TO THE
                                                ORDER OF                      V      O       I    D                              $
                                                                                                                                          DOLLARS
                                                               XXXXXX Services, X.X.
                                                               XXXXXXXXX, XXXXXXXX
                                                FOR
   
   
                                                     A031100160A08770194992865C1031
   
   
                                                               Interest and  Fee  Information
   
         APR for Check Cash Advances                        0% Promotional APR through your statement Closing Date in May 2013.
   
         Promotional Offer ID XXXX-XXXXX                    When this Promotional APR ends, the APR for these promotional balances will
                                                            increase to a Check Cash Advance rate of 24.99%.  This APR will vary with
                                                            the market based on the U.S. Prime Rate.
   
         Use  by Date                                       You must use these checks by September 9, 2012 for the promotional APR to
                                                            apply.  Any of these checks used after that date will be declined.
   
         Fee                                                4% of the amount of each transaction (min. $10).
   
   
         Paying  Interest                                   Wewill  begin charging  interest on these  checks  on the transaction date.
       Your account was selected for the following promotional offer based on your account status as of June 20, 2012. �
   
       Promotional Offer ID XXXX-XXXXXX:   The Promotional Annual Percentage Rate (Promotional APR) is 0% (.000000% Daily Periodic Rate 
       ("DPR")).  This promotional offer applies to Balance Transfers, Direct Deposit Cash Advances and Check Cash Advances bearing this Offer ID 
       (each an "eligible transaction").  This offer applies to eligible transactions posting to your account beginning July 11, 2012 through September 9, 
       2012.  This Promotional APR ends on your statement Closing Date in May 2013.  When this Promotional APR ends, the APR for Balance Transfer 
       promotional balances will increase to a variable rate based on the U.S. Prime Rate; as of June 30, 2012, this APR is 20.99%.  When this 
       Promotional APR ends, the APR for Direct Deposit and Check Cash Advance promotional balances will increase to a variable rate based on the 
       U.S. Prime Rate; as of June 30, 2012, this APR is 24.99%.  Use of an attached check or draft will constitute a charge against your credit account. 
       The transaction date for each Check Cash Advance or Balance Transfer made by check is the date you or the person to whom the check is made 
       payable first deposits or cashes the check.  
   
       The transaction fee for Balance Transfers, Direct Deposit Cash Advances and Check Cash Advances is 4% of the U.S. dollar amount of each 
       transaction (min. $10).  
       Minimum Interest Charge $1.50. 
       If you revolve your balance to take advantage of this promotion, all transactions and balances, including purchases, will be charged interest.
   
       � �  See Disclosures on Reverse side. 
  **************************** Page 6 ****************************
   

Here are the sample Output formats i would like to see.....

For Payments and Other Credits

Payments and Other Credits

Transaction   Posting                                             Reference   Account
   Date         Date     Description                                Number     Number     Amount       Total
                         
               06/18     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX     2459        XXXX      - 247.10

               07/09     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX     4383        XXXX      - 12.06
  07/09        07/10     PAYMENT - ELECTRONIC                       0050                  - 2,277.00
                                                                                                       - $2,536.16

For Purchases and Adjustments

Purchases and Adjustments

Transaction   Posting                                             Reference   Account
   Date         Date     Description                                Number     Number     Amount       Total

  06/09        06/11     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX     7683       XXXX       2.50        
  06/09        06/11     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX     7907       XXXX       1.25
  06/09        06/11     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX     6291       XXXX       21.28
  06/09        06/11     XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX     0917       XXXX       8.43
               ......................................
               ......................................
               ......................................
                                                                                                      $xxx.xx

For Fees

Fees                                                          
                                                          
Transaction   Posting                                             Reference   Account                  
   Date         Date     Description                                Number     Number     Amount       Total      

  07/07        07/07     LATE FEE FOR PAYMENT DUE 07/07             3214                  22.00
  07/10        07/10     CREDIT PROTECTION PLUS XXX.XXX.XXXX        500P                  9.47   
                         TOTAL FEES FOR THIS PERIOD                                                    $31.47   
   
Interest Charged   
   
  07/10        07/10          Interest Charged on Purchases                               0.00   
  07/10        07/10          Interest Charged on Balance Transfers                       0.00   
  07/10        07/10          Interest Charged on Dir Dep&Chk CashAdv                     0.00   
  07/10        07/10          Interest Charged on Bank Cash Advances                      0.00   
                              TOTAL INTEREST FOR THIS PERIOD                                            $0.00   
   

For Year-to-Date

2012 Totals Year-to-Date

Total fees charged in 2012           $122.93
Total interest charged in 2012       $0.00

For Year-to-Date:

$ sed -n "/2012 Totals Year-to-Date/,/Total interest charged in 2012/ {s/^ *//; p}" data
2012 Totals Year-to-Date

Total fees charged in 2012                              $122.93

Total interest charged in 2012                             $0.00

---------- Post updated at 06:35 PM ---------- Previous update was at 06:17 PM ----------

For Fees:

$ cat fees.sh
sed -n "/^ *Fees */, /TOTAL INTEREST FOR THIS PERIOD/ p" data > temp
echo "Transaction   Posting                                             Reference   Account" > output
echo "Date       Date           Description                                              Number       Number                 Amount            Total" >> output
tail -n +2 temp | cut -c 10- >> output
cat output
$ ./fees.sh
Transaction   Posting                                             Reference   Account
Date       Date           Description                                              Number       Number                 Amount            Total
07/07      07/07          LATE FEE FOR PAYMENT DUE 07/07                           3214                                22.00
07/10      07/10          CREDIT PROTECTION PLUS XXX.XXX.XXXX                      500P                                  9.47
                          TOTAL FEES FOR THIS PERIOD                                                                                  $31.47

                          Interest Charged

07/10      07/10          Interest Charged on Purchases                                                                  0.00
07/10      07/10          Interest Charged on Balance Transfers                                                          0.00
07/10      07/10          Interest Charged on Dir Dep&Chk CashAdv                                                        0.00
07/10      07/10          Interest Charged on Bank Cash Advances                                                         0.00
                          TOTAL INTEREST FOR THIS PERIOD                                                                               $0.00

Try this - purely based on the input provided

awk '/continued/{if(a==2){ha=1;a=1}if(b==2){b=1;hb=1}if(c==2){hc=1;c=1}next}
!x&&/Transaction Posting/{x=1;hdr=$0;getline;hdr=hdr"\n"$0;next}

!a&&/Payments and Other Credits/{a=1;next}
a==1&&/Payments and Other Credits/{a=2;if(!ha){print;print hdr}next}
a==2{print} a==2&&/\$/{a=-1;printf "\n"}

!b&&/Purchases and Adjustments/{b=1;next}
b==1&&/Purchases and Adjustments/{b=2;if(!hb){print;print hdr}next}
b==2{print} b==2&&/\$/{b=-1;printf "\n"}

!c&&/Fees/{c=1;next}
c==1&&/Fees/{c=2;if(!hc){print;print hdr}next}
c==2{print}/TOTAL INTEREST FOR THIS PERIOD/{c=-1;printf "\n"}

/Totals Year-to-Date/,/Total interest charged/{print}' infile

--ahamed