Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Delete First and last four rows from HUGE file

Posted on 2009-04-13
2
Medium Priority
?
260 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This tutorial is about how to put some of your C++ program's functionality into a standard DLL, and how to make working with the EXE and the DLL simple and seamless.   We'll be using Microsoft Visual Studio 2008 and we will cut out the noise; that i…
This article describes how to add a user-defined command button to the Windows 7 Explorer toolbar.  In the previous article (http://www.experts-exchange.com/A_2172.html), we saw how to put the Delete button back there where it belongs.  "Delete" is …
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 lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …

618 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