Solved

Delete First and last four rows from HUGE file

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Query performance - SQL Server 20 82
Visual Studio 2015 locks debug executable 9 186
Need to impress with my knowledge of .NET 5 90
Problem to file 3 76
This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

832 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