mIRC Home    About    Download    Register    News    Help

Topic Options
#136686 - 01/12/05 02:12 PM read the last 10 lines from file
bodo0815 Offline
Babel fish

Registered: 10/04/05
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

Top
#136687 - 01/12/05 04:29 PM Re: read the last 10 lines from file
RusselB Offline
Planetary brain

Registered: 03/08/04
Posts: 7252
Loc: Ontario, Canada
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
  }
}

 

Top
#136688 - 01/12/05 04:40 PM Re: read the last 10 lines from file
MikeChat Offline
Hoopy frood

Registered: 12/12/02
Posts: 1245
Loc: California, doooood
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.

Top
#136689 - 01/12/05 04:40 PM Re: read the last 10 lines from file
FiberOPtics Offline
Hoopy frood

Registered: 05/02/04
Posts: 2019
Loc: Leuven, Belgium
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.

Top
#136690 - 01/12/05 04:50 PM Re: read the last 10 lines from file
bodo0815 Offline
Babel fish

Registered: 10/04/05
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

Top