mIRC Home    About    Download    Register    News    Help

Print Thread
read from file and give x results #168372 08/01/07 12:43 AM
Joined: Jan 2007
Posts: 4
R
Revy Offline OP
Self-satisified door
OP Offline
Self-satisified door
R
Joined: Jan 2007
Posts: 4
Hello, I want to search something on a text file and message the results (max 5 results) on the channel.

I already did this code (see below) , but this code only gives me 1 result no more, even if I have more than 1 result on the text file.

Code:
on *:TEXT:*:#chan:{
  if ($1 == !search) && ($2 != $null) {
    set %ress $read(file.txt, w, $replace(* $+ $2- $+ *,$chr(32),*) )
    if (%ress != $null) {
    .timerM 1 1 msg #chan %ress }
    else { .timerM 1 1 msg #chan Nothing Found
    }
  }
}


What can I do to modify the code to give me X results?

Thanks

Re: read from file and give x results [Re: Revy] #168373 08/01/07 12:54 AM
Joined: Mar 2003
Posts: 612
B
billythekid Offline
Fjord artisan
Offline
Fjord artisan
B
Joined: Mar 2003
Posts: 612
you could use a /filter to pull all lines containing *whatever* then return those...

Code:
on *:TEXT:*:#chan:{
  if ($1 == !search) && ($2 != $null) {
    write -c results.txt
    filter -ff file.txt results.txt $replace(* $+ $2- $+ *,$chr(32),*)  
    if ($filtered) {
      var %i = 0
      while %i < 5 {
        inc %i
        msg $chan $read(results.txt,n,%i)
      }
    }
    else { msg #chan Nothing Found }
  }
}




billythekid
Re: read from file and give x results [Re: Revy] #168374 08/01/07 12:57 AM
Joined: Mar 2005
Posts: 420
X
xDaeMoN Offline
Fjord artisan
Offline
Fjord artisan
X
Joined: Mar 2005
Posts: 420
Try this, made by Quickstep
Code:
on *:TEXT:!search*:#:{
  ;-------- Set these vars --------
  var %file = FILE.txt, %maxsend = 5
  ;--------------------------------

  ;------- Code --------
  var %a = 1, %s = $+(*,$2-,*)
  :again
  if ($read(%file, nw, %s, $calc($readn + 1))) {
    tokenize 32 $ifmatch   
    if (%a <= %maxsend) msg # Match $+(no.,$v1) Link: $1 Description: $2-
    inc %a
  }
  if ($readn) goto again
  $iif(%a > %maxsend,msg # A total of $v1 matches were found only $v2 were displayed)
  $iif(!%a,msg # No matches found)
  ;---------------------
}


If you have a plastic floor runner over your tiles, then you're one Hella Pinoy!
Re: read from file and give x results [Re: xDaeMoN] #168381 08/01/07 02:15 AM
Joined: Jan 2007
Posts: 4
R
Revy Offline OP
Self-satisified door
OP Offline
Self-satisified door
R
Joined: Jan 2007
Posts: 4
Thanks for all the answers, it's working now laugh