Solved

Batch file Remove "ECHO is off " from output file

Posted on 2013-01-24
3
4,174 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 143

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 84

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

MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

Question has a verified solution.

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

Suggested Solutions

Have you ever had a hard drive that you can't boot into, but need to change the registry? Here is the solution! This article guides you through accessing and editing a registry of a non-primary drive. To read registry information on a non-prim…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
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…

856 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