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^"') DO while (records in the current logfile stille exist) ::insert a condition which checks whether the end of the log file is not reached yet DO 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) then copy line to a new log file elseif (TimestampInSeconds ge higherbound) :: if higher than the interval, increase the interval with a day and then lowerbound(loweverbound + aantal seconden van 1dag) higherbound(higherbound + aantal seconden van 1dag) done done