Kiran Sonawane
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)
2)
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
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
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"
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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
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
ASKER
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-exchang e.com/Prog ramming/La nguages/Sc ripting/Sh ell/Batch/ Q_28012103 .html
Here is one more question for you...
http://www.experts-exchang
FYI, another approach using VBS posted here:
https://www.experts-exchange.com/questions/28012352/batch-file-target-file-has-3-records-and-destination-file-has-4-records.html?anchorAnswerId=38830705#a38830705
~bp
https://www.experts-exchange.com/questions/28012352/batch-file-target-file-has-3-records-and-destination-file-has-4-records.html?anchorAnswerId=38830705#a38830705
~bp
ASKER