Solved

Batch file Remove "ECHO is off " from output file

Posted on 2013-01-24
3
4,086 Views
Last Modified: 2013-01-24

 Batch File code



@echo off
SETLOCAL ENABLEDELAYEDEXPANSION


bcp "select 'Name', 'EIN', 'AccountId', 'Other ID', 'Address Line 1', 'Address Line 2', 'City', 'State', 'Zip Code', 'Country', 'Other Data', 'Provider ID', 'Group ID' union all select * from testdb" queryout "C:\Data\CAAGBusinessFile.txt" -c -test\T_GSS -testuser -mypass

call :StripBlankLines CAAGBusinessFile.txt


bcp testdb out "C:\Data\CAAGIndividualsFile.TXT" -c -SNTSMSQL15011A\T_GSS -tesur -Ptest




call :StripBlankLines CAAGIndividualsFile.TXT


:StripBlankLines

For %%x in (%*) do set OutF=temp_(%%~nx).txt

::del %OutF%


for /F "tokens=* delims=" %%B in (%*) do echo %%B >> %OutF%

Goto :EOF

:End

Open in new window


Output
kiran	G	Sonawane		12	1	1	Rahatani		Pune	MH	41125	IN		O	1	1 
ECHO is off
test				233												 
Prakash	S	Tike		33	2	2	Don		K		456					1 

Open in new window

0
Comment
Question by:sonawanekiran
3 Comments
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 38813455
not sure which of the lines of code result in that line, and if nothing helps, you rework the file with another cat + find > newfile to skip that line ...
0
 
LVL 83

Accepted Solution

by:
oBdA earned 500 total points
ID: 38813481
Well, to only remove the "ECHO is off" line, you'll only have to replace the space between "echo" and "%%B" in line 25 with a dot: for /F "tokens=* delims=" %%B in (%*) do echo.%%B >> %OutF%; this will end up in an empty line. In addition, you'll need a "goto end" or "goto :eof" in line 17 (right before ":StripBlankLines") in order to avoid running into the procedure when the main script is done.
But from the script, it looks like you want to remove empty lines, but the "empty" line producing the "ECHO is off" seems to contain white spaces.
Try this:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION

bcp "select 'Name', 'EIN', 'AccountId', 'Other ID', 'Address Line 1', 'Address Line 2', 'City', 'State', 'Zip Code', 'Country', 'Other Data', 'Provider ID', 'Group ID' union all select * from testdb" queryout "C:\Data\CAAGBusinessFile.txt" -c -test\T_GSS -testuser -mypass
call :StripBlankLines "CAAGBusinessFile.txt"

bcp testdb out "C:\Data\CAAGIndividualsFile.TXT" -c -SNTSMSQL15011A\T_GSS -tesur -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

0
 
LVL 17

Author Closing Comment

by:sonawanekiran
ID: 38813713
@oBdA: You are champion 500+
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question