mIRC Home    About    Download    Register    News    Help

Print Thread
#156126 12/08/06 01:14 AM
Joined: Nov 2003
Posts: 101
C
colt45 Offline OP
Vogon poet
OP Offline
Vogon poet
C
Joined: Nov 2003
Posts: 101
I'm having trouble understand how to figure out how to use While Loop (tho, i may have choose the wrong one?).

What i'm trying to do is to read a log file, and removes unwanted lines then to display the rest of the results till end of the lines.

(i know it will flood me but i'm using //echo to my @windows box and it's only like 20-30 lines)

Could someone help?

#156127 12/08/06 02:36 AM
Joined: Jul 2004
Posts: 21
X
Ameglian cow
Offline
Ameglian cow
X
Joined: Jul 2004
Posts: 21
hm, there are two ways I can think of

First:
Code:
var %x = 1
var %file = text.log
while (%x <= $lines(%file)) {
  var %line = $read(%file,%x)
  if (*<unwanted line>* !iswm %line) {
    write newfile.txt %line
  }
  inc %x
}
  


And the second, which I've grown fond of. Reason being sometimes I mess up and end up with an infinite loop. With this second script, I can simply remove all text from the file and save, thus halting the loop.
Code:
var %x = 1
var %file = text.log
while ($read(%file,%x)) {
  if (*<unwanted line>* !iswm $ifmatch) {
    write newfile.txt $ifmatch
  }
  inc %x
}


Haven't really tested these, but I've used them so much, there is hardly any need to..

Last edited by xhine; 12/08/06 02:38 AM.
#156128 12/08/06 08:05 AM
Joined: Sep 2003
Posts: 4,230
D
Hoopy frood
Offline
Hoopy frood
D
Joined: Sep 2003
Posts: 4,230
OMG, using $lines(filename) in the while condition is one of the WORST things u can do!

Each and every time you do $lines(filename) mirc reads the whole file to get the number of lines.

Code:
var %x = 1, %file = text.log, %m = $lines(%file)
while (%x <= %m) {
  var %line = $read(%file,%x)
  if (*<unwanted line>* !iswm %line) { write newfile.txt %line }
  inc %x
}


A much nicer solution if it is just a simple !iswm would be.

//filter -ffx sourcefile destinationfile *<unwanted line>*
or
//filter -fwpx sourcefile @destinationwindow *<unwanted line>*

* the -x makes filter exclude the filter matched lines.

#156129 12/08/06 10:38 PM
Joined: Nov 2003
Posts: 101
C
colt45 Offline OP
Vogon poet
OP Offline
Vogon poet
C
Joined: Nov 2003
Posts: 101
Many thanks to both xhine and DaveC .. got it to works now smile


Link Copied to Clipboard