mIRC Home    About    Download    Register    News    Help

Print Thread
Replacing line in text file by wildcard #255267 04/10/15 01:33 AM
Joined: Jul 2015
Posts: 9
F
Fattyshow Offline OP
Nutrimatic drinks dispenser
OP Offline
Nutrimatic drinks dispenser
F
Joined: Jul 2015
Posts: 9
Code:
write -w<$nick> requests.txt $2- $+ ( $+ $nick $+ )


This part finds the line where the user's nickname is written.
Then it inserts the new $2- with his nick.

How do I make this so it deletes the old line and replaces it with the new one instead of inserting?

Last edited by Fattyshow; 04/10/15 01:33 AM.

Digital Rocker on Twitch TV - Bassist
Re: Replacing line in text file by wildcard [Re: Fattyshow] #255285 05/10/15 09:56 AM
Joined: Dec 2013
Posts: 779
N
Nillen Offline
Hoopy frood
Offline
Hoopy frood
N
Joined: Dec 2013
Posts: 779
$readn returns the line number which your wildcard search was matched, writing with -il $+ $readn will overwrite said line.
/help /write


Nillens @ irc.twitch.tv
Nillen @ irc.rizon.net
Re: Replacing line in text file by wildcard [Re: Fattyshow] #255323 08/10/15 12:45 PM
Joined: Jul 2006
Posts: 3,891
W
Wims Offline
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,891
The line you used is correct to overwrite a line, here is an example:
Code:
alias test_write {
write -c test LINE1 $+ $crlf $+ LINE2 $+ $crlf $+ LINE3
write -w"LINE2" test NEWLINE2
echo -a $read(test,tn,1) -- $read(test,tn,2) -- $read(test,tn,3)
.remove test
}


Nillens: $readn is only filled after a $read() call, using /write -w is much much better, $read will open the file, check all the line, try to match them, then on a match, fills $readn, close the file. You would then use /write -l $readn, which would open the file, go to the $readn line, and replace it. In short, the whole $read part can be avoided, speeding up the processing greatly.

Last edited by Wims; 08/10/15 12:48 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel