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: ...
30th October 2012, 11:31 AM #1
- 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)
IDG Tech News
30th October 2012, 12:02 PM #2
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...
By David92595 in forum Scripts
Last Post: 6th July 2011, 12:24 AM
By leeshellard in forum ICT KS3 SATS Tests
Last Post: 21st March 2011, 04:23 PM
By ahuxham in forum Scripts
Last Post: 17th November 2009, 04:10 PM
By russdev in forum Courses and Training
Last Post: 6th April 2009, 01:16 PM
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Tags for this Thread