Sign in to follow this  
Followers 0
Fire

Extract and write next every 1000 lines?

3 posts in this topic

#1 ·  Posted (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 host

This 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.log

What 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 by Fire

[size="5"] [/size]

Share this post


Link to post
Share on other sites



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)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

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]

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0