1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Splitting Log Into Individual Files

Discussion in 'Software Development' started by JuniperGreen, Feb 15, 2013.

Thread Status:
Not open for further replies.
  1. JuniperGreen

    JuniperGreen Thread Starter

    Jan 3, 2013
    I'm stuck with a script again and would appreciate it if anyone can help point me in the right direction. I have a long rolling log which I want to split up into individual files. The following is indicative of the start of entries where each starts on a new line followed by an unpredictable number of lines of text:

    I want to split the above into:


    concatenating the contents into one file when the entry shows the same file name and has a suffix of _01, _02, _03 etc. I have only coded for 6 suffixes but there are likely to be more than that. A single file entry will always be _01.

    I had to insert @@@ into the log on the line above every file entry for 2 reasons - 1) as a delimiter for splitting the file for the Array and 2) I need to preserve the line with the file details as I need it as the first line in the split file and as subsequent headings where there is concatenation. (Using the line with the file as a delimiter doesn't work for me as it is removed when loaded into the array).

    I thought I had cracked it but not so. I was also aiming to have split files numbered consecutively but I couldn't achieve that. I would get the first file as 1 and the second one as 8 etc. I can wear the split file numbers not being consecutive if I could get the log split properly.

    Const ForReading = 1
    Const ForAppending = 8
    strPath = "F:\Test\"
    strFile1 = "Append_Txt.txt"
    strFile2 = "MSplit.txt"
    strDeLimit = "@@@"
    'Read Text File Into String
    set fso = CreateObject("Scripting.FileSystemObject")
    Set objTextfile = fso.OpenTextFile(strPath & strFile1,ForReading,False)
    'Load String Into Array
    OutPutArray = split(strContents,strDeLimit,-1,1)
    'Close File
    'Check For Sections
    'Read Each Element of Array Into Memory for OutPut
    For each strCurrentLine in outputArray
    'Open File For Appending
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set objfile = fso.OpenTextFile(strPath & n & strFile2,ForAppending,True)
    'Scroll through conditions
    for n = 1 to 6
    if instr(1,strCurrentLine,"_00",1) >0 then
    strTotal = strCurrentLine
    end if
    if instr(1,strCurrentLine,"_01",1) >0 then
    strTotal = strTotal + strCurrentLine
    end if
    if instr(1,strCurrentLine,"_02",1) >0 then
    strTotal = strTotal + strCurrentLine
    end if
    if instr(1,strCurrentLine,"_03",1) >0 then
    strTotal = strTotal + strCurrentLine
    end if
    if instr(1,strCurrentLine,"_04",1) >0 then
    strTotal = strTotal + strCurrentLine
    end if
    if instr(1,strCurrentLine,"_05",1) >0 then
    strTotal = strTotal + strCurrentLine
    end if
    'Write Array Element To File
    'Increment Counter
    'Close File
As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1089627

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice