Hmm, I have the feeling that there are some misunderstandings here. It seems that there are several headers and several footers, not just one of each in the file. Possibly even one header and one footer for each record. It is also not entirely clear whether the headers and footers are on the same line at the data. Can you please give a sample of your file so that we can understand better its structure?