mIRC Homepage
Posted By: Frog /write stuff. - 16/03/04 07:06 PM
Yeah. I'm trying to get /write to use the -w"Text" switch..so it searches the file for the line containing "Text" and perform the action on it..

It doesn't seem to be working..I'm using like this (for testing) right now:

/write -dw"This is a test" file.txt

The line "This is a test" is in the file, but it's not being deleted like it should be.

What I'm really trying to do is have it search for the line specified, and replace it with whatever. Can I do that with /write alone?

Thanks?
Posted By: Frog Re: /write stuff. - 16/03/04 07:14 PM
Well, I just made a work-around using $read and $readn, but still, according to the help file I should be able to do what I want with /write alone..

So, am I just reading the help file wrong, or can you indeed do what I'm looking to? And if so..what am I doing wrong?

Thanks.
Posted By: Frog Re: /write stuff. - 16/03/04 08:13 PM
Now there's a new problem..

I made this to work around the previous problem:

Code:
alias mp3r {
  if ($msn) {
    if (!$read(Mp3Rank.txt,nw,$+(*,$msn,*))) {
      write -n Mp3Rank.txt $msn : 1
      return $read(Mp3Rank.txt,w,$+(*,$msn,*))
    }
    write $+(-l,$readn) Mp3Rank.txt $msn : $calc($gettok($read(Mp3Rank.txt,n,$msn),2,58) + 1)
  }
}


Now..that will write to the file in this format:

Artist - Track : [number of times played]

And it works..until it gets four different lines in the file. Then, instead of making a new line, it appends to the last one. Anyone know what causes that, or yet ANOTHER thing I can do to work around this?

Posted By: Iori Re: /write stuff. - 16/03/04 09:19 PM
Well, /write -dw"match text" works just fine, but must be an exact match or a wildcard match, ie if there is a trailing space the line won't match that example, but would match -dw"match text*", or you could use the -r switch for a regex search.
Try /write -w"This is a test*" file.txt
To overwrite, you omit the d /write -w"This is a test*" file.txt Replacement text Again the exact match comes into it.
Posted By: Frog Re: /write stuff. - 16/03/04 09:48 PM
I was using that earlier.
Code:
    write -w"$+($msn,*)" Mp3Rank.txt $msn : $calc($gettok($read(Mp3Rank.txt,n,$msn),2,58) + 1)


Doesn't work for me. Instead of replacing the string, it just appends to the end of it.

$msn = current song playing, in the format "Artist - Song : [num]"
Posted By: Iori Re: /write stuff. - 16/03/04 09:54 PM
write -w"$+($msn,*)" <-is invalid, use $+(-w",$msn,*")
Posted By: Frog Re: /write stuff. - 16/03/04 09:59 PM
Tried that after I saw what I posted, and it didn't work either.
Posted By: Frog Re: /write stuff. - 16/03/04 10:51 PM
Nevermind, I got it.

The -n switch in the first /write was messing things up..

*Feels like a moron*
© mIRC Discussion Forums