mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Jan 2003
Posts: 2
O
owenw Offline OP
Bowl of petunias
OP Offline
Bowl of petunias
O
Joined: Jan 2003
Posts: 2
I am trying to use the /write command to delete the last line in a text file (which is a blank line). I tried using:

/write -d file.txt

as the Mirc help says not specifying a line number will remove the last line in a file. In fact, this will remove the last line in a file that contains any text, but if the last line is blank, it will remain!

I also tried using $crlf to remove any carriage returns. This will remove blank lines in a text file EXCEPT for the last line! Can someone please help me?

Thanks in advance.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
mirc automatically adds a CRLF as the last line when it writes to the file, but I don't see why this is a problem since that last line is ignored (for example, $lines() does not include that last line). Anyway, if you want to remove the ending CRLF you can use /btrunc:
Code:
/btrunc file.txt $calc($file(file.txt) - 2)



You can also check if the file ends in CRLF:
Code:
//bread file.txt $calc($file(file.txt) - 2) 2 &a | if ($bvar(&a,1-) == 13 10) { do stuff }


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
/write -dl $lines(filename.txt) filename.txt


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
That won't delete the empty line at the end (the CRLF), it will delete the one before that, which will probably be a line of text. That's what I meant that mirc ignores the last line if it's a CRLF. Both /write and $lines 'ignore' the last blank line.

/write always appends that blank line at the end of the file so I don't see any other way than binary commands.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Dec 2002
Posts: 1,321
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Dec 2002
Posts: 1,321
Ooops. Sorry, I misread the question.


DALnet: #HelpDesk and #m[color:#FF0000]IR[color:#EEEE00]C
Joined: Dec 2002
Posts: 1,237
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Dec 2002
Posts: 1,237
LOL im sorry but i cant resist no longer

<funny remark>
Well you could locate the file itself on your computer...When you do this click on the text file you want to open it....then go to the last line in the text file and do the following:

1. highlight the last line in the file and click delete
2. Save the file since it has changed
</funny remark>

Ok you now may go back to the original discussion now that i have said this i can go back to not hiding my laughter LOL
thanks for sitting through my B/S


Link Copied to Clipboard