mIRC Home    About    Download    Register    News    Help

Print Thread
#145156 19/03/06 06:56 PM
Joined: Feb 2006
Posts: 22
B
BIGZIPZ Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Feb 2006
Posts: 22
I am trying to read 10 lines from a text file called Comics.txt and I want it to increase the var %matrhfound by 1 every time it finds a line in the text file which starts with DC: e.g:

DC: What Golden Age mystery-man was aided by the Newsboy Legion?

This is what I have so far and I cannot seem to get it working, am I missing something? Thank you

alias temp1 {
while (%iii <= 10) {
if (*DC* isin ($read(C:\Comics.txt, s, *DC*, %iii))) inc %matchfound 1
inc %iii 1
}
}

#145157 19/03/06 07:46 PM
Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
Try this code:
Code:
alias countlines {
  if (!$0) return
  var %f = 0, %i = 0
  while ($read(test.txt,w,$1-,%i)) {
    %i = $calc($readn + 1)
    inc %f
  }
  return %f
}


Usage:
$countlines(*wild*)

Example:
//echo -a $countlines(*DC*)

Result:
Returns number of matching lines.

-genius_at_work

#145158 19/03/06 09:18 PM
Joined: Feb 2006
Posts: 22
B
BIGZIPZ Offline OP
Ameglian cow
OP Offline
Ameglian cow
B
Joined: Feb 2006
Posts: 22
Thank you very much, works a treat.

#145159 20/03/06 09:03 AM
Joined: Feb 2004
Posts: 2,019
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2004
Posts: 2,019
That's an inefficient approach.

Preferable would be:

Code:
alias countlines {
  var %file = $+(",$1,")
  if (!$isfile(%file)) || (* !iswm $2) return 
  filter -ff %file nul $2 
  return $filtered
}

$countlines(versions.txt,*var*)
$countlines(c:\my files\doc.txt,*item*)


Gone.

Link Copied to Clipboard