mIRC Home    About    Download    Register    News    Help

Print Thread
read the last 10 lines from file #136686 01/12/05 02:12 PM
Joined: Apr 2005
Posts: 72
B
bodo0815 Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Apr 2005
Posts: 72
hello...
sorry for this post, in know there are thousands of posts
with this question but nothings for me :-(

i need a script thats read the LAST 10 lines from a txt
if nothing was found ...msg $chan nothing found...
i have a little script:
Code:
on *:TEXT:!test *:#: {
  filter -cff search.txt filter_search.txt * $+ $2- $+ *
  var %x = $calc($lines(filter_search.txt) -9)
  while (%x <= $lines(filter_search.txt)) {
    msg $chan $read(filter_search.txt,%x)
    inc %x
  }
}

it works fine but how insert the line if nothing was found?

thy bodo

Re: read the last 10 lines from file #136687 01/12/05 04:29 PM
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Code:
 on *:TEXT:!test *:#: {
  filter -cff search.txt filter_search.txt $+(*,$2-,*)
  var %x = $calc($lines(filter_search.txt) -9)
if %x = -9 {
msg $chan No entires found
}
elseif %x < 0 {
msg $chan Only $calc(%x + 9) entries found
}
 while (%x <= $lines(filter_search.txt)) {
    msg $chan $read(filter_search.txt,%x)
    inc %x
  }
}

 

Re: read the last 10 lines from file #136688 01/12/05 04:40 PM
Joined: Dec 2002
Posts: 1,245
M
MikeChat Offline
Hoopy frood
Offline
Hoopy frood
M
Joined: Dec 2002
Posts: 1,245
well you might look at /loadbuf
Quote:

/loadbuf [lines] [-pirsgleopcnmNt<topic>] <window | dialog id> <filename>
Loads the specified number of lines from the end of the file of filename into the specified window.

/loadbuf 20 @test info.txt

This loads the last 20 lines of info.txt into custom window @test.


in the help for /filter
This command also fills the $filtered identifier with the number of matches found, if any.
$filtered
Returns the number of lines that were filtered when using the /filter command.

so you can use something like:
if ($filtered == $null) to retun something if no matches were found
if (!$filtered) { write filter_search.txt No Matches Found }

instead of the while loop, look at using play
or loadbuf savebuf I think will do what you want.

Re: read the last 10 lines from file #136689 01/12/05 04:40 PM
Joined: Feb 2004
Posts: 2,019
FiberOPtics Offline
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
When you perform a /filter, the identifier $filtered will return the number of filtered lines.

So after you issue your filter command, you check for:

if ($filtered) {
; matches were found
}
else {
; nothing was found
}

EDIT: fixed typo


Gone.
Re: read the last 10 lines from file #136690 01/12/05 04:50 PM
Joined: Apr 2005
Posts: 72
B
bodo0815 Offline OP
Babel fish
OP Offline
Babel fish
B
Joined: Apr 2005
Posts: 72
my script only post results if found 10 matches :-(
Code:
elseif %x &lt; 0 {
msg $chan Only $calc(%x + 9) entries found

how can i post results if only one match?

bodo