Results 1 to 16 of 16

Thread: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    READ backward A very, very BIG FILE TXT (approx 6.000.xxx of lines) , how to?

  2. #2
    PowerPoster Nightwalker83's Avatar
    Join Date
    Dec 2001
    Location
    Adelaide, Australia
    Posts
    13,344

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    What do you mean "backwards" reading from right to left instead of left to right or reading the file from bottom to top?
    when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
    If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
    https://get.cryptobrowser.site/30/4111672

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    I suspect it's bottom up... and it's being written to by something else, and all the OP is interested in is the new info that's at the bottom... all without having to first read the first 5,999,999 rows.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    where does the VERY BIG FILE TXT come from ?
    cant it be written the correct way around at start ?

    : )

  5. #5
    PowerPoster
    Join Date
    Jan 2008
    Posts
    11,074

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Maybe that's not the point


    Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.

  6. #6

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Quote Originally Posted by Nightwalker83 View Post
    What do you mean "backwards" reading from right to left instead of left to right or reading the file from bottom to top?
    sorry...
    ... from bottom to top?

    adding new notice, the file is arround 156 mb.

  7. #7

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Quote Originally Posted by techgnome View Post
    I suspect it's bottom up... and it's being written to by something else, and all the OP is interested in is the new info that's at the bottom... all without having to first read the first 5,999,999 rows.

    -tg
    hi Tg....

    I have tested a various code to store the file in array and then loop it from bottom to the top and read line with a for next -1, or tested a lbound to unbound ...
    But all codee tested go in error because use a big memory.

  8. #8
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    read the file for binary in chunks (whatever size suits) from end, split the chunks into lines, add the end line of next chunk to first line of last chunk, calculate remaining bytes to read first lines in file
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  9. #9
    PowerPoster Zvoni's Avatar
    Join Date
    Sep 2012
    Location
    To the moon and then left
    Posts
    4,418

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Another important information (at least in my opinion): Are those Lines in this TXT-File structured as in "Do all lines have the same length"?
    Last edited by Zvoni; Tomorrow at 31:69 PM.
    ----------------------------------------------------------------------------------------

    One System to rule them all, One Code to find them,
    One IDE to bring them all, and to the Framework bind them,
    in the Land of Redmond, where the Windows lie
    ---------------------------------------------------------------------------------
    People call me crazy because i'm jumping out of perfectly fine airplanes.
    ---------------------------------------------------------------------------------
    Code is like a joke: If you have to explain it, it's bad

  10. #10
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Here's a simple implementation of Westconn1's suggestion.
    Code:
    Option Explicit
    
    Private Sub Command1_Click()
    Dim intFile As Integer
    Dim intFirst As Integer
    Dim intI As Integer
    Dim intK As Integer
    Dim binLast As Boolean
    Dim lngPos As Long
    Dim lngLen As Long
    Dim lngBlk As Long
    Dim strBuffer As String
    Dim strLines() As String
    Dim strFile As String
    Dim strTemp As String
    lngBlk = 2000
    strFile = "c:\MyDir\reverse.txt"
    intFile = FreeFile()
    Open strFile For Binary As intFile
    lngLen = LOF(intFile)
    If lngLen < lngBlk Then lngBlk = lngLen
    lngPos = lngLen - lngBlk + 1
    Do
        strBuffer = Space(lngBlk)
        Get #intFile, lngPos, strBuffer
        intFirst = InStr(strBuffer, vbNewLine)
        intFirst = intFirst + 2
        strTemp = Mid$(strBuffer, intFirst)
        strLines = Split(strTemp, vbNewLine)
        For intI = UBound(strLines) To 0 Step -1
            Debug.Print strLines(intI)
        Next intI
        lngPos = lngPos - lngBlk + intFirst - 3
    Loop Until lngPos < 0
    lngBlk = lngBlk + lngPos
    lngPos = 1
    strBuffer = Space(lngBlk)
    Get #intFile, lngPos, strBuffer
    strLines = Split(Mid$(strBuffer, 1, Len(strBuffer) - 1), vbCrLf)
    For intI = UBound(strLines) To 0 Step -1
        Debug.Print strLines(intI)
    Next intI
    Close intFile
    End Sub
    It reads an entire file 'backwards' - you may want to stop it after a certain number of records.

  11. #11

    Thread Starter
    PowerPoster
    Join Date
    Mar 2005
    Posts
    2,580

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Quote Originally Posted by westconn1 View Post
    read the file for binary in chunks (whatever size suits) from end, split the chunks into lines, add the end line of next chunk to first line of last chunk, calculate remaining bytes to read first lines in file
    in chunks (whatever size suits)?????


    Code example please?

  12. #12
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Quote Originally Posted by luca90 View Post
    Code example please?
    See Post #10

  13. #13
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    lngBlk = 2000
    funny that was the value i used too
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  14. #14
    PowerPoster
    Join Date
    Jul 2006
    Location
    Maldon, Essex. UK
    Posts
    6,334

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Quote Originally Posted by westconn1 View Post
    funny that was the value i used too
    Great Minds think alike etc.

  15. #15
    Hyperactive Member Rattled_Cage's Avatar
    Join Date
    Dec 2005
    Posts
    315

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    Code:
    Shell "sort /R c:/order.txt /o c:/sorted.txt"
    would that help ?
    Last edited by Rattled_Cage; Oct 25th, 2013 at 09:06 AM. Reason: tags

  16. #16
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: READ backward A VERY BIG FILE TXT (approx 6.000.xxx of lines)

    What is the reason for wanting to read it bottom up and do you actually need to read the whole file or just the last part of it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width