mIRC Home    About    Download    Register    News    Help

Print Thread
How do I delete the last line of a text file?!? #12286 21/02/03 09:08 AM
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.

Re: How do I delete the last line of a text file?!? #12287 21/02/03 09:41 AM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
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
Re: How do I delete the last line of a text file?!? #12288 21/02/03 11:28 AM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
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
Re: How do I delete the last line of a text file?!? #12289 21/02/03 06:12 PM
Joined: Jan 2003
Posts: 2,523
Q
qwerty Offline
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
Re: How do I delete the last line of a text file?!? #12290 22/02/03 12:48 AM
Joined: Dec 2002
Posts: 1,321
H
Hammer Offline
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
Re: How do I delete the last line of a text file?!? #12291 22/02/03 02:05 AM
Joined: Dec 2002
Posts: 1,237
T
The_Game Offline
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