Fire Posted January 30, 2011 Share Posted January 30, 2011 (edited) Hello Dears,Please help:(I have intrusionlogs.log file(Log file) which contains > 150k lines in it.File structure:Snippet from that file:Intrusion attempt1 unixtime(somenumbers) browserstring remote host Intrusion attempt2 unixtime(somenumbers) browserstring remote host Intrusion attempt3 unixtime(somenumbers) browserstring remote hostThis file generated by Mysql DB (using crontab) Something like this:mysql -A -H --tee=sessions.txt -h localhost -u mysqluser -pmysecretstrongpass -e "select attempt as 'Intrusion attempt',from_unixtime(time) as 'Unixtime',browser as 'browserstring',host as 'remote host' from instrusiontable order by time desc limit 0,1000">>intrusionlogsN.logWhat i want to do:Devide this file to N number to another files (say intrusion1k.log, intrusin2k.log and etc.) by EVERY next 1000 lines from intrusionlogs.log .I mean read every 1000 lines from intrusionlogs.log and write to intrusion1k.log where k=1000 etc.Guys,I'm really missing some logic in this task.Some calculation seems there.I'm planning using filereadline() funcsion for this task.Because _FileReadToArray() is not usefull in this situation for me (Very big log file)Any direction please.How to realise every next 1000 lines thing?I'm sorry again because i'm without code here.But really i can'not find logic for my self in this task.Any directions please.Thanks in advance. Edited January 30, 2011 by Fire [size="5"] [/size] Link to comment Share on other sites More sharing options...
Developers Jos Posted January 30, 2011 Developers Share Posted January 30, 2011 untested but should be close to what you want: $FileCnt = 1 $RecCnt = 0 $infile = FileOpen("inputlog.txt", 0) $outfile = FileOpen("intrusion1k.log", 2) ; Check if file opened for reading OK If $infile = -1 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 $line = FileReadLine($infile) If @error = -1 Then ExitLoop $RecCnt += 1 If $RecCnt > 1000 Then FileClose($outfile) $FileCnt += 1 $RecCnt = 1 $outfile = FileOpen("intrusion1" & $FileCnt& "k.log", 2) EndIf FileWriteLine($outfile,$line) Wend ; FileClose($infile) FileClose($outfile) SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past. Link to comment Share on other sites More sharing options...
Fire Posted January 30, 2011 Author Share Posted January 30, 2011 Hi Jos. Worked Like charm! Thank you 1000 times for this. Now i'm Going to catch logic of your script.. Thanks again. Solved. [size="5"] [/size] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now