Tuesday, September 20, 2011

dos batch script to remove last line


::-----bo Batchl....
@echo off & setlocal
 
Set FirstLine=True
 
:: Delete the existing file so that it can be created with latest data
IF EXIST ggg.txt (del /Q ggg.txt)
 
For /F "tokens=*" %%i in ('findstr /V "Text in last line" "InputFile.txt"') do call :doSomething "%%i"
goto :eof
 

:: This function will check if it is the first line to be printed or it will print new line before printing next line
:doSomething
Set ThisLine="%~1"
 
IF %FirstLine%==True (
Set FirstLine=False
) ELSE (
echo. >> OutputFile.txt
)
call :printLine %ThisLine%
goto :eof
 
:: This function prints a text without next line
:printLine
for %%a in ("%~1") do (
echo/|set /p =%%a
) >> OutputFile.txt
 
:eof
::-----eo Batch....  

No comments:

Post a Comment