Solved

Batch file Remove "ECHO is off " from output file

Posted on 2013-01-24
3
3,890 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 82

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
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). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now