mIRC Homepage
Posted By: dak How many times 1 wildcard appears in a .txt file - 11/03/03 05:27 AM
im working on a script to check how many times a wildcard (specified in a trigger) appears in a rather large .txt file full of quotes.

eg: .qammount mirc
would return somthing like: "mirc" found in 13/417 quotes.

i thought i had it, but i'm stumped

what i'm trying to do, is make the script read every line by looping a string like this
Code:
 $read(C:\bot\bot_log_pub.txt, %currentline)
%currentline would be set to $calc($readn + 1) to check the next line

to stop the loop i would just use an if statement (if %currentline == %totalquotes) where %totalquotes would read "line 0" in the .txt file, line 0, if you didnt know, is a number that represents the total number of lines in the .txt file

basicly all i need to know, is how to scan only 1 line at a time, instead of the whole document.
thanks in advance - dak

ps: if you have a different way of completing my objective, feel free to post it, any help will be appriciated
Here is the code I came up with:
Code:
on *:TEXT:.qammount*:#:{
  var %l = 1,%r = 0
  while ( $read([color:green]test.txt[/color],w,* $+ $2- $+ *,%l) != $null ) {
    var %l = $readn + 1
    inc %r
  }
  msg # " $+ $2 $+ " found in %r $+ / $+ $read([color:green]test.txt[/color],0) quotes.
}


P.S. You could use $lines(test.txt) rather than $read(test.txt,0), it would save you having to fiddle around with the first number of the file everytime you added/removed a quote (if that's what you're doing, that is).
i appriciate your help, but...

that code, along with my other attempts, infinite loops and crashes the bot.

also, i never have to open the quote file to change anything because when you add a quote, it adds 1 to the line that lists how many lines there are, and it subtracts one if i delete a line.
It wouldn't crash for me, you sure you don't have another one of your attempts still loaded? confused bah, oh well
well the wierd thing is, almost every time i try to use $null in a loop, it ends up doing that. Do i just suck with if-then-else statements or is somthing wrong with $null? crazy
Another (faster) solution is /filtering the source file to a dummy window and checking $filtered to tell how many lines matched.
Code:

on *:TEXT:.qammount *:#:{
  window -h @@
  filter -fw file.txt @@ * $+ $2-*
  window -c @@
  msg # There were $filtered lines matching to ' $+ $2-'
}
i found somthing that didnt infinite loop

Code:
 on *:text:.qammount *:#:{ 
  set %line 1
  set %r 0  
  while ($read(C:\bot\bot_log_pub.txt, w, * $+ $2- $+ *, %line) != $null) {
    %line = $readn + 1
    inc %r
  }
  msg # " $+ $2- $+ " found in %r $+ / $+ $read(C:\bot\bot_log_pub.txt, 0) quotes.
}
 
Use $lines(file) instead of $read(file,0)
Use the filtered one.. it's way faster, smaller and better.
© mIRC Discussion Forums