Matthias Tacke wrote:
> "Phil Robyn [MVP]" wrote:
>
>
>>Alan Tang wrote:
>>
>>>Hello:
>>>
>>> Is it possible to delete the last character from the text file?
>>>
>>>Thanks!
>>>
>>
>>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::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
> <snip>
>
> Hello Phil,
> I'm a bit curious, I always got rec:~0,-1 in the output.
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. :-)
>
> The echo status on empty lines is also present. This worked (but not
> with html files where the last char is a closing bracket ;-)
The original poster's "the text file" was not specific enough. Of course,
depending on what is actually in a particular file, one may have to make
certain modifications (for example, to write out blank lines, etc.) And
html files where the last character is a closing bracket might also pose
a problem. But in general, it is indeed *possible* to remove the last
character from a text file via a batch file; it's just that a batch file
might not be the most *practical* means of doing so, depending on what is
in the text file in question.
>
> ::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::::::::::::::::::::::::::::::::::::::::::::::::::::::
>
>
--
Phil Robyn
Univ. of California, Berkeley
u n z i p m y a d d r e s s t o s e n d e - m a i l
|