mIRC Home    About    Download    Register    News    Help

Print Thread
#20776 24/04/03 10:26 PM
Joined: Dec 2002
Posts: 204
K
keeker Offline OP
Fjord artisan
OP Offline
Fjord artisan
K
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:

Code:
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.
#20777 25/04/03 12:40 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Code:
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

#20778 25/04/03 12:45 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Try this:
Code:
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
#20779 25/04/03 12:50 AM
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
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 smile

There's a little typo in ...$line(@!,$line(@!,0)1)


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
#20780 25/04/03 01:01 AM
Joined: Dec 2002
Posts: 699
N
Fjord artisan
Offline
Fjord artisan
N
Joined: Dec 2002
Posts: 699
Thanks for pointing out that typo smile
Your way is definatley faster, I forgot all about the -r switch for /filter laugh

#20781 25/04/03 02:37 AM
Joined: Dec 2002
Posts: 204
K
keeker Offline OP
Fjord artisan
OP Offline
Fjord artisan
K
Joined: Dec 2002
Posts: 204
thanks qwerty, its working pretty good now. smile grin


keek: Scots - intr.v. keeked, keekĀ·ing, keeks
To peek; peep.

Link Copied to Clipboard