A
Alan Tang
Hello:
Is it possible to delete the last character from the text file?
Thanks!
Is it possible to delete the last character from the text file?
Thanks!
Alan said:Hello:
Is it possible to delete the last character from the text file?
Thanks!
<snip>Phil Robyn said:Yes! It is possible! See the post by Matthias Tacke in the "Trim
Last Line" thread. The following is a slight modification to remove
the last character.
::StripLastChar.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::
Matthias said::
<snip>
Hello Phil,
I'm a bit curious, I always got rec:~0,-1 in the output.
The echo status on empty lines is also present. This worked (but not
with html files where the last char is a closing bracket ;-)
::StripLastChar.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
if not exist %1 goto :eof
for /f %%A in ('find /V /C "" ^<%1') do set lines=%%A
for /f "tokens=1,* delims=[]" %%A in ('find /V /N "" ^<%1') do (
if %%A LSS %lines% (
echo/%%B
) else (
set "rec=%%B"
call echo.%%rec:~0,-1%%
)
)
::StripLastChar.cmd::::::::::::::::::::::::::::::::::::::::::::::::::::::
No critic Phil, just a correction for my own mistake. The way with thePhil Robyn said:Hi, Matthias,
Well, unlike my usual practice, I didn't actually *test* the suggested
code; I merely copied your example and made what I thought would be the
appropriate change.![]()