mIRC Homepage
Posted By: droplogic lil $read help - 23/03/04 10:57 PM
I'm trying to write something that'll search the last 50 lines of a file, for a certain word, and if it finds it..echo's the last line out of those 50 that has that word in it.

Example..let's say hello.txt has 200 lines in it. I'm trying to get it to search lines 150-200 for the word "hello", and if it finds it, echo's it. So if it found a "hello" in line 170 and 190..it would only echo line 190.

any ideas?

Edited:

This..
msg # $iif($read(hello.txt, w, *hello*, $calc($lines(hello.txt) - 1)),$read(hello.txt, n, $readn))
..keeps giving me Insufficient Parameters. It works just fine if i put it at -10 or -9, but nothing below that. Is it because the last 8 lines of the hello.txt begin with (1)hello or (2)hello..etc?

Edited:

N/m, know why it's not working. Anyone got another idea that'd work?
Posted By: Online Re: lil $read help - 24/03/04 05:55 AM
alias scanfile1 {
var %text = * $+ $$1-*, %file = file.txt, %lines = $lines(%file)
var %pos = $iif(%lines < 50,0,$calc(%lines - 50))
while $read(%file,wn,%text,%pos) {
var %found = $ifmatch, %pos = $readn + 1
}
if %found { echo -a * %found }
}

alias scanfile2 {
var %text = * $+ $$1-*, %file = file.txt, %lines = $lines(%file)
var %pos = $iif(%lines < 50,0,$calc(%lines - 50))
window -h @@
filter -fwr $+(%pos,-,%lines) %file @@ %text
echo -a * $line(@@,$filtered)
close -@ @@
}

Pick your favorite (I prefer the latter) and use: /scanfileN text
Posted By: droplogic Re: lil $read help - 24/03/04 02:05 PM
Aha. Nice nice man. Although I'd probably have better luck understanding Chinese algebra, but it works heh.
Thanks a ton!
Posted By: Online Re: lil $read help - 24/03/04 11:24 PM
You're welcome. I'm not good at commenting code, but if you're stuck with a command just post back laugh
Posted By: droplogic Re: lil $read help - 25/03/04 12:18 AM
heh trying to redo it in tcl since mirc doesnt like being run under local system acct for some reason, but tcl is even more complicated, it seems.
© mIRC Discussion Forums