+ Post New Thread
Results 1 to 2 of 2
Scripts Thread, Copying lines from multiple logfiles, based on line content in Coding and Web Development; I have multiple log files of 10mb each. The content of the log files always look like this: 06.09.2012, 21:36:02:83: ...
  1. #1

    Join Date
    Oct 2012
    Thank Post
    Thanked 0 Times in 0 Posts
    Rep Power

    Copying lines from multiple logfiles, based on line content

    I have multiple log files of 10mb each. The content of the log files always look like this:

    06.09.2012, 21:36:02:83: xxxxx yyyyyy zzz
    06.09.2012, 21:36:02:84: xx yyy zzz
    06.09.2012, 21:36:05:24: xxxxxxxxx yyyyyyyyyy zzzz

    The log files are in the same folder and have the following names File01.log, File02.log, etc.

    I want to create a new log file for every hour. This new log file can contain lines from multiple log files, since a file can end at 21:36:05 because it reached the 10 mb. The next logfile will then continue from that point of time. It is thus very random at what time a log file ends. One thing however is for sure. File02.log always follows up File01 and so further.

    My idea was to execute it in a .bat, using a for /f loop to loop through all files and parse out the date and time from the logging. I wanted to convert the date and time to seconds and compare this to an hour interval (which is also in seconds). If the time in seconds is bigger than the interval, the interval should be increased with an hour (both lower and upper bound).

    I had something in mind like the following code. I however have not much experience in programming so I am not sure if this is possible. Perhaps one of you guys can give me a push in the right direction or provide me with a solution.

    FOR /f "tokens=1,2 delims= " %%G in ('dir /O:N /b/s ^"C:\logs\R\*.log^"') 
    while (records in the current logfile stille exist) ::insert a condition which checks whether the end of the log file is not reached yet
    DateFromRecord = %%G :: parse out the date
    TimeFromRecord = %%H :: parse out the time
    :: Make a variable that combines both the date and the time to a timestamp
    :: Create a function that turns the timestamp into seconds
    if (TimestampInSeconds ge lowerbound AND TimestampInSeconds lt higherbound) ::compare the time from file with the interval (in seconds)
    copy line to a new log file
    elseif (TimestampInSeconds ge higherbound) :: if higher than the interval, increase the interval with a day and 
    lowerbound(loweverbound + aantal seconden van 1dag)
    higherbound(higherbound + aantal seconden van 1dag)

  2. #2

    tom_newton's Avatar
    Join Date
    Sep 2006
    Thank Post
    Thanked 851 Times in 673 Posts
    Rep Power
    You already have the "hour" in an integer format.. keep spitting lines to your first hours file until that changes, then change filename. I would suggest perl is the language for this...

+ Post New Thread

Similar Threads

  1. Replies: 0
    Last Post: 5th July 2011, 11:24 PM
  2. ASDAN On-line eAssessment
    By leeshellard in forum ICT KS3 SATS Tests
    Replies: 12
    Last Post: 21st March 2011, 03:23 PM
  3. VBS - wshell.run based on file contents?
    By ahuxham in forum Scripts
    Replies: 14
    Last Post: 17th November 2009, 03:10 PM
  4. Free security awareness training on-line from InfraGard.
    By russdev in forum Courses and Training
    Replies: 2
    Last Post: 6th April 2009, 12:16 PM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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