mIRC Home    About    Download    Register    News    Help

Print Thread
#76279 23/03/04 10:57 PM
Joined: Feb 2004
Posts: 16
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Feb 2004
Posts: 16
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?

#76280 24/03/04 05:55 AM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
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

#76281 24/03/04 02:05 PM
Joined: Feb 2004
Posts: 16
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Feb 2004
Posts: 16
Aha. Nice nice man. Although I'd probably have better luck understanding Chinese algebra, but it works heh.
Thanks a ton!

#76282 24/03/04 11:24 PM
Joined: Dec 2002
Posts: 1,922
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,922
You're welcome. I'm not good at commenting code, but if you're stuck with a command just post back laugh

#76283 25/03/04 12:18 AM
Joined: Feb 2004
Posts: 16
D
Pikka bird
OP Offline
Pikka bird
D
Joined: Feb 2004
Posts: 16
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.


Link Copied to Clipboard