mIRC Home    About    Download    Register    News    Help

Print Thread
script that will search a txt file 4 sumtin then.. #135476 12/11/05 06:13 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
i need a script where it will search a script file for something then dlt it - but the prob is i know u can use the command write -dsWORD filename.txt

but if the text file was like

WORD bla
WORD bla2
WORD bla3

it would only delete WORD bla and would leave the other two there.

Re: script that will search a txt file 4 sumtin th #135477 12/11/05 07:11 AM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
You can just make a simple while loop for that.

Code:
while ($read([color:red]file.txt[/color], w, [color:red]search-term[/color] $+ *) != $null) {
  write -ds $+ [color:red]search-term[/color] [color:red]file.txt[/color]
}

Re: script that will search a txt file 4 sumtin th #135478 12/11/05 07:21 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
whered $1 come from

Re: script that will search a txt file 4 sumtin th #135479 12/11/05 07:27 AM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Sorry, it should have been the search-term, I just forgot to replace it.

I've edited the code.

Re: script that will search a txt file 4 sumtin th #135480 12/11/05 07:34 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
everytime i use the command 2 things happen

1) when u try to open the txt file, wordpad comes up saying failed to open (but sometimes u can get in)

2) Mirc Lags out

i think their might b sumtin wrong with the loop but i dunno

EDIT: dunno about this but can a line ever be $null ?

Last edited by onesikgypo; 12/11/05 07:36 AM.
Re: script that will search a txt file 4 sumtin th #135481 12/11/05 07:36 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
Your code would only delete the first instance.

Code:
alias moo {
  var %x = $lines(test.txt)
  while (%x) {
    if ($+($1,*) iswm $read(test.txt,%x)) write $+(-dl,$readn) test.txt
    dec %x
  }
}


-Andy

Re: script that will search a txt file 4 sumtin th #135482 12/11/05 07:44 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
modified it to this

Code:
on *:TEXT:!dlt:?:{
  moo
}
alias -l moo {  
  var %x = $lines(incompletefiles.txt)  while (%x) {    
    if ($+(onesikgypo,*) iswm $read(incompletefiles.txt,%x)) {
      write $+(-dl,$readn) incompletefiles.txt
      dec %x
    }
  }
}


and in incompletefiles

Code:
onesikgypo===============================
onesikgypo bla
onesikgypo bla2
onesikgypo bla3
sadf bak


i msg the bot with !dlt and nothing happens

Re: script that will search a txt file 4 sumtin th #135483 12/11/05 07:44 AM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
You must have misread the code, because it does deletes every instance found. I tested with the following alias before I posted it.

Code:
alias deltxt {
  while ($read(test.txt, w, $1 $+ *) != $null) {
    write -ds $+ $1 test.txt
  }
}


test.txt contained these lines:
line 1
line 2
line 3
4th line
5th line

After doing "/deltxt line" it leaves only:
4th line
5th line

Re: script that will search a txt file 4 sumtin th #135484 12/11/05 07:50 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
That lags the hell out of mIRC, and doesnt delete any lines for me.. smile

-Andy

Re: script that will search a txt file 4 sumtin th #135485 12/11/05 07:51 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
alright i used ur code exactly how u used it just changed the text file, so

Code:
alias deltxt {
  while ($read(incompletefiles.txt, w, $1 $+ *) != $null) {
    write -ds $+ $1 incompletefiles.txt  
  }
}


then typed /deltxt onesikgypo

again mirc client just lags

Re: script that will search a txt file 4 sumtin th #135486 12/11/05 07:53 AM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline
Fjord artisan
Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
That's very strange then, it works without problems here.

Tried on both mIRC 6.14 and with my bot 6.16, it works fine on either, though I don't think the version should be a problem.

Re: script that will search a txt file 4 sumtin th #135487 12/11/05 07:55 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
lol damn this is annoying
Code:
alias moo {
  var %x = $lines(incompletefiles.txt)  while (%x) {
    if ($+($1,*) iswm $read(incompletefiles.txt,%x)) write $+(-dl,$readn) incompletefiles.txt
    dec %x 
  }
}


typed /moo onesikgypo

nothing dlted

can i ask where u got $readn from, or sumtin , i dunno not workin 4 me

Re: script that will search a txt file 4 sumtin th #135488 12/11/05 08:01 AM
Joined: Dec 2002
Posts: 3,547
S
SladeKraven Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 3,547
$readn is the last line read from the text file.

The code does work, you just dont have it on the lines as I have it. Copy the code from the forum, paste in wordpad (/run wordpad) and then paste in the editor. Or just make sure you put the lines of code exactly how I have it.

-Andy

Re: script that will search a txt file 4 sumtin th #135489 12/11/05 08:05 AM
Joined: Oct 2005
Posts: 122
O
onesikgypo Offline OP
Vogon poet
OP Offline
Vogon poet
O
Joined: Oct 2005
Posts: 122
blah didnt realise it, lol works now, thnx

Re: script that will search a txt file 4 sumtin th #135490 12/11/05 09:23 AM
Joined: Dec 2002
Posts: 2,962
S
starbucks_mafia Offline
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
A much simpler and much much more efficient way to do this is:

Code:
filter -ffx [color:blue]filename.txt filename.txt[/color] [color:green]searchtext[/color] *

(Yes, the filename should be written twice).

This way the file is only opened and edited once, whereas using the other ways you've been shown here mIRC is effectively opening the file, looking at it, and closing it, twice per matching line using the $read() searching method, or in for the line-looping method it's actually opening the file, looking at it, and closing it twice per line - that's potentially hundreds of times for a relatively small file!


Spelling mistakes, grammatical errors, and stupid comments are intentional.