Solved Delete last line of a .txt file by using Batch

March 14, 2013 at 18:19:59
Specs: Windows server 2008 r2
i want to delete the last line of a .txt file if it is blank.i don't want to wright the result in a new file.

Is it possible by using a Batch File.

See More: Delete last line of a .txt file by using Batch

Report •

March 15, 2013 at 15:18:15
✔ Best Answer
Unfortunately no, batch scripts cannot amend a file in situ, the result must be written to a new file.

Please come back & tell us if your problem is resolved.

Report •

March 18, 2013 at 00:13:18
As Wahine indicates, bat can't read/write to a file at the sa,e time.

:: ===== script starts here ===============
:: delete last line if blank
:: noLASTb.bat 2013-03-18 13:48:22.12
@echo off > newfile & setLocal enableDELAYedeXpansioN

for /f "tokens=1* delims=[]" %%a in ('find /n /v "" ^< myfile') do (
) >> newfile
move /y newfile myfile
goto :eof
::====== script ends here =================

M2 Golden-Triangle

Report •

Related Solutions

Ask Question