mIRC Home    About    Download    Register    News    Help

Print Thread
How many times 1 wildcard appears in a .txt file #14907
11/03/03 05:27 AM
11/03/03 05:27 AM
Joined: Mar 2003
Posts: 9
D
dak Offline OP
Nutrimatic drinks dispenser
dak  Offline OP
Nutrimatic drinks dispenser
D

Joined: Mar 2003
Posts: 9
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

Last edited by dak; 11/03/03 05:30 AM.

______________________________

123go
Re: How many times 1 wildcard appears in a .txt file #14908
11/03/03 06:02 AM
11/03/03 06:02 AM
Joined: Dec 2002
Posts: 3,138
London, UK
C
Collective Offline
Hoopy frood
Collective  Offline
Hoopy frood
C

Joined: Dec 2002
Posts: 3,138
London, UK
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).

Re: How many times 1 wildcard appears in a .txt file #14909
11/03/03 06:29 AM
11/03/03 06:29 AM
Joined: Mar 2003
Posts: 9
D
dak Offline OP
Nutrimatic drinks dispenser
dak  Offline OP
Nutrimatic drinks dispenser
D

Joined: Mar 2003
Posts: 9
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.

Last edited by dak; 11/03/03 06:33 AM.

______________________________

123go
Re: How many times 1 wildcard appears in a .txt file #14910
11/03/03 06:33 AM
11/03/03 06:33 AM
Joined: Dec 2002
Posts: 3,138
London, UK
C
Collective Offline
Hoopy frood
Collective  Offline
Hoopy frood
C

Joined: Dec 2002
Posts: 3,138
London, UK
It wouldn't crash for me, you sure you don't have another one of your attempts still loaded? confused bah, oh well

Re: How many times 1 wildcard appears in a .txt file #14911
11/03/03 06:38 AM
11/03/03 06:38 AM
Joined: Mar 2003
Posts: 9
D
dak Offline OP
Nutrimatic drinks dispenser
dak  Offline OP
Nutrimatic drinks dispenser
D

Joined: Mar 2003
Posts: 9
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


______________________________

123go
Re: How many times 1 wildcard appears in a .txt file #14912
11/03/03 07:20 AM
11/03/03 07:20 AM
Joined: Dec 2002
Posts: 1,922
O
Online Offline
Hoopy frood
Online  Offline
Hoopy frood
O

Joined: Dec 2002
Posts: 1,922
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-'
}

Re: How many times 1 wildcard appears in a .txt file #14913
11/03/03 07:25 AM
11/03/03 07:25 AM
Joined: Mar 2003
Posts: 9
D
dak Offline OP
Nutrimatic drinks dispenser
dak  Offline OP
Nutrimatic drinks dispenser
D

Joined: Mar 2003
Posts: 9
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.
}
 


______________________________

123go
Re: How many times 1 wildcard appears in a .txt file #14914
11/03/03 09:01 AM
11/03/03 09:01 AM
Joined: Dec 2002
Posts: 1,922
O
Online Offline
Hoopy frood
Online  Offline
Hoopy frood
O

Joined: Dec 2002
Posts: 1,922
Use $lines(file) instead of $read(file,0)

Re: How many times 1 wildcard appears in a .txt file #14915
12/03/03 05:31 PM
12/03/03 05:31 PM
Joined: Feb 2003
Posts: 810
Brazil
C
cold Offline
Hoopy frood
cold  Offline
Hoopy frood
C

Joined: Feb 2003
Posts: 810
Brazil
Use the filtered one.. it's way faster, smaller and better.


* cold edits his posts 24/7