mIRC Home    About    Download    Register    News    Help

Print Thread
#99885 06/10/04 10:06 PM
Joined: Jul 2004
Posts: 21
X
xhine Offline OP
Ameglian cow
OP Offline
Ameglian cow
X
Joined: Jul 2004
Posts: 21
im using something similar to like:
Code:
 
 alias readtxt {
  var %x = 1
  while ($read(file.txt,n,%x)) {
    var %line = $gettok($ifmatch,1-,32)
    if (%line > 5000) { write newfile.txt %line }
    inc %x
  }
}


an exmaple of the txt file would be like:

1
2
3
4

5
6

7


etc.. with spaces in between. I spent a good hour or so trying to figure it out, but whatever i tried, it stops when it reaches the return(by that i mean it wont read after 4[after the 'enter'])
Any idea how to make it keep going?
i tried doing
Code:
  
while (%line == $null) { inc %x }

but it doesnt even read after the 4 to see its $null, any ideas?

Last edited by xhine; 06/10/04 10:07 PM.
#99886 07/10/04 03:02 AM
Joined: Jan 2003
Posts: 3,012
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2003
Posts: 3,012
compar %x <= $lines(file.txt) instead of comparing the value.


-KingTomato
#99887 07/10/04 09:33 PM
Joined: Aug 2003
Posts: 1,831
I
Hoopy frood
Offline
Hoopy frood
I
Joined: Aug 2003
Posts: 1,831
Here's a couple of alternate methods which should be speedier.

If you want to disregard empty lines and copy from line 5001 even if there are empty lines
Code:
alias readtxt {
  if $lines(file.txt) &gt; 5000 {
    filter -cffr $+(5001-,$v1) file.txt newfile.txt *
  }
}


If you only want to copy anything following the text "5000"
Code:
alias readtxt {
  if $read(file.txt,w,5000) &amp;&amp; $readn &lt; $lines(file.txt) {
    filter -cffr $+($calc($v1 +1),-,$v2) file.txt newfile.txt
[color:gray]    ; Remove the line above and uncomment the one below to prevent empty lines in newfile.txt.
    ;    filter -[color:blue]x[/color]cffr $+($calc($v1 +1),-,$v2) file.txt newfile.txt [color:blue]$crlf[/color][/color]
  }
}


Using the file handlng tools.
Code:
alias freadtxt {
  .fopen abc1 file.txt
  if $ferr { .fclose abc1 | return }
  .fopen -no abc2 newfile.txt
  .fseek -w abc1 5000* | .echo -q $fread(abc1)
  while !$feof {
    if $fread(abc1) { .fwrite -n abc2 $v1 } 
  }
  .fclose abc?
}


Link Copied to Clipboard