Solved

Delete First and last four rows from HUGE file

Posted on 2009-04-13
2
223 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
2 Comments
 
LVL 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

910 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now