Solved

Delete First and last four rows from HUGE file

Posted on 2009-04-13
2
251 Views
Last Modified: 2012-05-06
I have a very large text file that contains over 7 million rows of data.  I need to delete the first and last four rows from the file.  

The file is too huge to read in as an array, so I was trying to use a text stream.  I successfully used TextStream to get the row count, but I do not know how to stream the text out and not send the first and last four rows .

Any help would be appreciated.
0
Comment
Question by:ddpleasant
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 24130772
you will need to "buffer" 4 rows (which will be the last 4 rows "not" to write into the file at the end).


it shall look almost like this (untested):
f = fso.OpentextFile(..., forreading)
d = fso.OpentextFile(..., forWriteing)
dim arrLines()
dim arrPointer
dim lngLine
dim strLine 
lngLine = 0
'build the 0-based array with 4 items:
arrLines = split(",,,", ",")
arrPointer = lbound(arrLines) 
while not f.AtEndOfStream
  strLine = f.ReadLine
  lngLine = lngLine + 1 
  if lngLine > 4 then
    if lngLine >= 8
      'write out the item in the array to the destination file
      d.WriteLine arrLines(arrPointer)
    end if 
    'set pointer to next item
    arrPointer = arrPointer + 1
    if arrPointer > ubound(arrLines) then
      arrpointer = lbound(arrLines)
    end if 
    arrLines(arrPointer) = strLine
  end if
wend 
d.Close
f.Close

Open in new window

0
 

Author Closing Comment

by:ddpleasant
ID: 31569529
Thank you!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question