mIRC Home    About    Download    Register    News    Help

Topic Options
#20776 - 24/04/03 11:26 PM search log files
keeker Offline
Fjord artisan

Registered: 15/12/02
Posts: 204
Loc: Iowa, USA
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.

Top
#20777 - 25/04/03 01:40 AM Re: search log files
Nimue Offline
Hoopy frood

Registered: 08/12/02
Posts: 699
Loc: Sunshine, Oz.
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

Top
#20778 - 25/04/03 01:45 AM Re: search log files
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
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

Top
#20779 - 25/04/03 01:50 AM Re: search log files
qwerty Offline
Hoopy frood

Registered: 07/01/03
Posts: 2523
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

Top
#20780 - 25/04/03 02:01 AM Re: search log files
Nimue Offline
Hoopy frood

Registered: 08/12/02
Posts: 699
Loc: Sunshine, Oz.
Thanks for pointing out that typo smile
Your way is definatley faster, I forgot all about the -r switch for /filter laugh

Top
#20781 - 25/04/03 03:37 AM Re: search log files
keeker Offline
Fjord artisan

Registered: 15/12/02
Posts: 204
Loc: Iowa, USA
thanks qwerty, its working pretty good now. smile grin
_________________________
keek: Scots - intr.v. keeked, keekˇing, keeks
To peek; peep.

Top