Solved

Delete First and last four rows from HUGE file

Posted on 2009-04-13
2
213 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This article shows how to make a Windows 7 gadget that accepts files dropped from the Windows Explorer.  It also illustrates how to give your gadget a non-rectangular shape and how to add some nifty visual effects to text displayed in a your gadget.…
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 …
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…
This video discusses moving either the default database or any database to a new volume.

708 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

12 Experts available now in Live!

Get 1:1 Help Now