Consulting

Results 1 to 10 of 10

Thread: wrap broken lines in one line in a given text or log file

  1. #1
    VBAX Regular
    Joined
    Feb 2022
    Posts
    24
    Location

    wrap broken lines in one line in a given text or log file

    How to wrap broken lines in one line in a given big text file ?

    Example input text file:


    1. I'm looking for some vba that will do the . following:*
    1. create smaller text files from a larger one
    2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line,
    find the key word, and then begin the copy including that line of key word of text.
    4. If same key word is found, the copy should end before
    that line.
    5. After that, the copied text was transferred to a new
    text file.
    The original file will be located under C:\Temp.


    1. create smaller text files from a larger one
    2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line,
    find the key word, and then begin the copy including that line of key word of text.
    4. If same key word is found, the copy should end before
    that line.
    5. After that, the copied text was transferred to a new
    text file.
    The original file will be located under C:\Temp.
    #####


    3. The plan is to look for a particular key word in a line,
    find the key word, and then begin the copy including that line of key word of text.
    4. If same key word is found, the copy should end before
    that line.
    5. After that, the copied text was transferred to a new
    text file.
    The original file will be located under C:\Temp.


    1. create smaller text files from a larger one 2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line,
    find the key word, and then begin the copy including that line of key word of text. 4. If same key word is found, the copy should end before
    that line.
    5. After that, the copied text was transferred to a new text file.
    The original file will be located under C:\Temp.
    #####
    ----------------------------------------------------------------------------------------above text will be file1 in C:\Temp


    2. do the . following: I'm looking for some vba that will
    1. create smaller text files from a larger one


    2. I simply require a specific section of the text file (its a log file).
    3. The plan is to look for a particular key word in a line, find the key
    word, and then begin the copy including that
    line of key word of text.


    4. If same key word is found, the copy should end before that line.
    5. After that, the copied text was transferred to a new text file.
    The original file will be located under C:\Temp.
    1. create smaller text files from a larger one
    2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line,
    find the key word, and then begin the copy including that line of key word of text.
    4. If same key word is found, the copy should end before
    that line.
    5. After that, the copied text was transferred to a new
    text file.
    The original file will be located under C:\Temp.



    1. create smaller text files from a larger one
    2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line,
    find the key word, and then begin the copy including that line of key word of text.
    4. If same key word is found, the copy should end before
    that line.
    5. After that, the copied text was transferred to a new
    text file.
    The original file will be located under C:\Temp.
    ----------------------------------------------------------------------------------------above text will be file2 in C:\Temp


    3. I'm looking for some vba that will do the . following:
    1. create smaller text files from a larger one


    2. I simply require a specific section of the text file (its a log file).
    3. The plan is to look for a particular key word in a line, find the key word,
    and then begin the copy including that line of key word of text.
    4. If same key word is found, the copy should end before that line.
    5. After that, the copied text was transferred to a new text file.
    The original file will be located under C:\Temp.
    ----------------------------------------------------------------------------------------above text will be file3 in C:\Temp

    Example output text file:

    1. I'm looking for some vba that will do the . following:* 1. create smaller text files from a larger one 2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line, find the key word, and then begin the copy including that line of key word of text. 4. If same key word is found, the copy should end before that line. 5. After that, the copied text was transferred to a new text file. The original file will be located under C:\Temp.


    1. create smaller text files from a larger one 2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line, find the key word, and then begin the copy including that line of key word of text. 4. If same key word is found, the copy should end before that line. 5. After that, the copied text was transferred to a new text file. The original file will be located under C:\Temp. #####


    3. The plan is to look for a particular key word in a line, find the key word, and then begin the copy including that line of key word of text. 4. If same key word is found, the copy should end before that line. 5. After that, the copied text was transferred to a new text file. The original file will be located under C:\Temp.


    1. create smaller text files from a larger one 2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line, find the key word, and then begin the copy including that line of key word of text. 4. If same key word is found, the copy should end before that line. 5. After that, the copied text was transferred to a new text file. The original file will be located under C:\Temp. ##### ----------------------------------------------------------------------------------------above text will be file1 in C:\Temp


    2. do the . following: I'm looking for some vba that will 1. create smaller text files from a larger one


    2. I simply require a specific section of the text file (its a log file). 3. The plan is to look for a particular key word in a line, find the key word, and then begin the copy including that line of key word of text.


    4. If same key word is found, the copy should end before that line. 5. After that, the copied text was transferred to a new text file. The original file will be located under C:\Temp. 1. create smaller text files from a larger one 2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line, find the key word, and then begin the copy including that line of key word of text. 4. If same key word is found, the copy should end before that line. 5. After that, the copied text was transferred to a new text file. The original file will be located under C:\Temp.



    1. create smaller text files from a larger one 2. I simply require a specific section of the text file (its a log file).


    3. The plan is to look for a particular key word in a line, find the key word, and then begin the copy including that line of key word of text. 4. If same key word is found, the copy should end before that line. 5. After that, the copied text was transferred to a new text file. The original file will be located under C:\Temp. ----------------------------------------------------------------------------------------above text will be file2 in C:\Temp


    3. I'm looking for some vba that will do the . following: 1. create smaller text files from a larger one


    2. I simply require a specific section of the text file (its a log file). 3. The plan is to look for a particular key word in a line, find the key word, and then begin the copy including that line of key word of text. 4. If same key word is found, the copy should end before that line. 5. After that, the copied text was transferred to a new text file. The original file will be located under C:\Temp. ----------------------------------------------------------------------------------------above text will be file3 in C:\Temp

  2. #2
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    How can we help if you have no notion of VBA at all ?

  3. #3
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,192
    Location
    There is quite a lot of detail missing to be able to put something together that will do the job so instead i have created my own text file and keyword.
    The example below will pull everything out of the text file in between the words 'Apple' & 'Apple', hold it in an array and then dump it in a new text file saved to the same path.

    The import file has been named 'Input"
    The file it will create will be named 'Output'

    You should be able to use the logic to do what you need.

    Sub test()    
        Dim FileToRead As Scripting.TextStream
        Dim FileToWrite As Scripting.TextStream
        Dim TextString As String
        Dim FSO As New FileSystemObject
        Dim kWord As String, x As Long, y As Long
        Dim var As Variant
        Dim txtFilePath As String
        Dim oVar() As Variant
        
        kWord = "Apple"
        txtFilePath = "C:\Users\jbloggs\Desktop\test\"
        
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set FileToRead = FSO.OpenTextFile(txtFilePath & "Input.txt", ForReading)
        TextString = FileToRead.ReadAll
        FileToRead.Close
        var = Split(TextString, kWord)
        For x = 1 To UBound(var) Step 2
            ReDim Preserve oVar(y)
            oVar(y) = var(x)
            y = y + 1
        Next x
        Set FileToWrite = FSO.CreateTextFile(txtFilePath & "Output.txt", True)
        FileToWrite.WriteLine Join(oVar, vbNewLine)
        FileToWrite.Close
    End Sub
    Output file has been uploaded for reference
    Attached Files Attached Files
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  4. #4
    VBAX Regular
    Joined
    Feb 2022
    Posts
    24
    Location
    Hi,

    Dim FileToRead As Scripting.TextStream
    Showing Compile Error: User-Defined type not defined.

    Quote Originally Posted by georgiboy View Post
    There is quite a lot of detail missing to be able to put something together that will do the job so instead i have created my own text file and keyword.
    The example below will pull everything out of the text file in between the words 'Apple' & 'Apple', hold it in an array and then dump it in a new text file saved to the same path.

    The import file has been named 'Input"
    The file it will create will be named 'Output'

    You should be able to use the logic to do what you need.

    Sub test()    
        Dim FileToRead As Scripting.TextStream
        Dim FileToWrite As Scripting.TextStream
        Dim TextString As String
        Dim FSO As New FileSystemObject
        Dim kWord As String, x As Long, y As Long
        Dim var As Variant
        Dim txtFilePath As String
        Dim oVar() As Variant
        
        kWord = "Apple"
        txtFilePath = "C:\Users\jbloggs\Desktop\test\"
        
        Set FSO = CreateObject("Scripting.FileSystemObject")
        Set FileToRead = FSO.OpenTextFile(txtFilePath & "Input.txt", ForReading)
        TextString = FileToRead.ReadAll
        FileToRead.Close
        var = Split(TextString, kWord)
        For x = 1 To UBound(var) Step 2
            ReDim Preserve oVar(y)
            oVar(y) = var(x)
            y = y + 1
        Next x
        Set FileToWrite = FSO.CreateTextFile(txtFilePath & "Output.txt", True)
        FileToWrite.WriteLine Join(oVar, vbNewLine)
        FileToWrite.Close
    End Sub
    Output file has been uploaded for reference

  5. #5
    VBAX Regular
    Joined
    Feb 2022
    Posts
    24
    Location
    Actually I want to "remove-line-breaks". But I need the out as shown.
    Here is an online tool with default settings that does the same: https://www.gillmeister-software.com...ne-breaks.aspx
    But my text file is big so I need help to do it with VBA.

    Quote Originally Posted by snb View Post
    How can we help if you have no notion of VBA at all ?

  6. #6
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,192
    Location
    You will need to add a reference to the Scripting Runtime in the VBE for it to work.
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

  7. #7
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    You'd better use 'late binding'.

  8. #8
    VBAX Regular
    Joined
    Feb 2022
    Posts
    24
    Location
    In an easy way what it will be ?
    Quote Originally Posted by georgiboy View Post
    You will need to add a reference to the Scripting Runtime in the VBE for it to work.

  9. #9
    VBAX Regular
    Joined
    Feb 2022
    Posts
    24
    Location
    'late binding' ?
    Quote Originally Posted by snb View Post
    You'd better use 'late binding'.

  10. #10
    Moderator VBAX Master georgiboy's Avatar
    Joined
    Mar 2008
    Location
    Kent, England
    Posts
    1,192
    Location
    Quote Originally Posted by ucan View Post
    In an easy way what it will be ?
    In the window where you paste the code:
    Tools
    References
    Search for: Microsoft Scripting Runtime
    Check the box
    Click here for a guide on how to add code tags
    Click here for a guide on how to mark a thread as solved

    Excel 365, Version 2403, Build 17425.20146

Tags for this Thread

Posting Permissions

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