Solved

Batch file Remove "ECHO is off " from output file

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Nmap how to find wich type of socks is this? 4 118
robocopy vs xcopy vs copy 8 156
Bat File Script - HELP 2 34
Windows 10 ISO build version 3 50
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
If like me you are one who spends a lot of time working and scripting with cmd.exe, sometimes it is handy to be able to quickly view a calendar for a given month and year. This script will quickly do just that!  Save the code posted below to a .bat …
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…
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…

733 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