Read large text File and write out 5000 records

I have a 1 Gig file with ~ 17 million lines called truex.txt.  I need to read or stream in the file ,and look for a string of "000000000000".  When the line contains that string, write that line out to a file c:\temp\sample.txt.   I need to stop after writing out 5000 lines.

I have not done VB in years, so a code snippet would be appreciated.

Thank you,
Who is Participating?
Robberbaron (robr)Connect With a Mentor Commented:

also can be done using VBS & FSO.
see authot comment at end of

Sub GetTest()
dim sFileIn as string, sFileOut as string, sDataLine as string
dim lFi as long, lFo as long, lCount as long
sFileIn= "truex.txt"
sFileOut = "c:\temp\sample.txt"
open sFileIn for input as lfi
lFo = FreeFile
open sFileOut for Output as lFo
do while not eof(lfi) and lCount < 5000
    line input #lFi, sDataLine
    if instr(sDataLine,"000000000000") > 0 then
         'found desired line
         print #lFo,sDataLine
         lCount = lCount+1
    end if
close lFo
close lFi
end sub

Open in new window

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.