Link to home
Start Free TrialLog in
Avatar of Kiran Sonawane
Kiran SonawaneFlag for India

asked on

Batch file not removing last blank line

I tried both way to remove last line in text file which is output of batch file . See below batch file code

1)

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION



bcp tbltest out "C:\Data\CAAGIndividualsFile.TXT" -c -SQLINST\T -testuser -Ptest
call :StripBlankLines CAAGIndividualsFile.TXT


goto :eof
:StripBlankLines
For %%x in ("%~1") do set OutF=temp_%%~nx.txt
if exist "%OutF%" del "%OutF%"
for /F "usebackq delims=" %%B in (%*) do (
	call :TrimWS %%B
	if not "!Line!"=="" >>"%OutF%" echo !Line! 
)
goto :eof

:TrimWS
set Line=%*
goto :eof 

:End
               
                                  

Open in new window




2)

@echo off
setlocal EnableDelayedExpansion

bcp tbltest out "%TEMP%\CAAGIndividualsFile.TXT" -c -SQLINST\T -testuser -Ptest
findstr /V /R /B /E /C:" *" "%TEMP%\CAAGIndividualsFile.TXT">"C:\Data\CAAGIndividualsFile.TXT"
                                            

Open in new window


But still both batch file not removing last blank line. See the attached text file which is output from both batch file. There is still blank line at the end of record.

Please help out..
output.TXT
ASKER CERTIFIED SOLUTION
Avatar of oBdA
oBdA

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Kiran Sonawane

ASKER

Thanks Boss.... 500*4   ..  :)
Avatar of Bill Prew
Bill Prew

Agreed, there was no blank line at the end of the file you showed.  It is normal for a Windows text file to have a <CR><LF> pair at the end of every line, including the last line.

Just curious, why do you need to strip off the "end of line" from the last line? Typically that won't cause a problem with any program that deals with text files.

~bp
Actually this text file is using third party tool (I don't know about this). They asked me to remove last blank line. And then I asked to you... :)

Here is one more question for you...

http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_28012103.html