|
Joined: Dec 2002
Posts: 204
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 204 |
i am trying to make a script to search log files. What i need is a way to search a monthly log for text, which i have done with:
alias scanfile {
var %svar $2-
window -elk0 @test
filter -fw $curlogfile @test *%svar*
savebuf @test savedlogfilename.txt
send $1 savedlogfilename.txt
timerdelfile 1 40 remove savedlogfilename.txt
}
right now that works ok, if someone types stats send *keeker*kicked*neoknight* , i have an ontext event that runs scanfile $nick %text and it searches the log file for the specified text, but what i WANT it to do is be able to search for the text and return the part of the log that contains it, not just the line, but like 15 lines before that and 15 lines after it. like if i was searching for if someone was kicked and they didnt think they deserved it, an SOP could retrive that part of the log file, becaue if they retrived the whole log file, its like over 3 MB right now fo the month, thats a lot to send if the SOP has a 56k modem. was wondering if there is a way to do something like this?
keek: Scots - intr.v. keeked, keekĀ·ing, keeks To peek; peep.
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
alias scanfile2 {
window -h @!
filter -fw $curlogfile @! $+(*,$2-,*)
; check for a match, and find the line number of the last match.
if $filtered && $read($curlogfile,w,$line(@!,$line(@!,0))) {
; load/save/send the range of lines
loadbuf $+($iif($calc($readn -15) > 0,$ifmatch,1),-,$calc($readn +15)) -r @! $curlogfile
savebuf @! $mkfn($1) $+ .scan.txt
dcc send $1 $mkfn($1) $+ .scan.txt
}
window -c @!
}
on *:filesent:*.scan.txt:.remove $filename
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Try this: alias scanfile {
if $read($curlogfile,nw,* $+ $$2-*) == $null { .notice $1 No matches found | return }
var %file [color:red]=[/color] $+(savedlogfilename,$ticks,.txt)
filter -ffcr $iif($calc($readn -15) > 0,$ifmatch,1) $+ $calc(-15 - $readn) $curlogfile %file
if $file(%file) { dcc send -c $1 %file }
.timer $+ %file -oi 2 40 .remove %file
}
on *:filesent:savedlogfilename?*: .timer $+ $nopath($filename) off | .remove $+(",$filename,") The key feature here is /filter's -r switch, which allows you to define a line range in the input file. Notice that you don't need the @window. Also, imo, you should make it a habit of using "=" in /var, otherwise you'll run into problems sooner or later. If you want to increase the line range, change both instances of 15 to a higher number. If you are worried about the size of the output file, consider compressing the file prior to sending it, perhaps with Necroman's ngzipn.dll (you can find it at the mircscripts.org DLL section), and have the receiver's script decompress it. Alternatively, you could use winzip/winrar's commandline tools for this.
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Jan 2003
Posts: 2,523
Hoopy frood
|
Hoopy frood
Joined: Jan 2003
Posts: 2,523 |
Ah, you already replied by the time I hit "Send". Your way, that grabs the last match instead of the first makes more sense too There's a little typo in ...$line(@!,$line(@!,0) 1)
/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
|
|
|
|
Joined: Dec 2002
Posts: 699
Fjord artisan
|
Fjord artisan
Joined: Dec 2002
Posts: 699 |
Thanks for pointing out that typo Your way is definatley faster, I forgot all about the -r switch for /filter
|
|
|
|
Joined: Dec 2002
Posts: 204
Fjord artisan
|
OP
Fjord artisan
Joined: Dec 2002
Posts: 204 |
thanks qwerty, its working pretty good now.
keek: Scots - intr.v. keeked, keekĀ·ing, keeks To peek; peep.
|
|
|
|
|