remove blank line - windows 7 scripting - to avoid "Echo is off"

hi

I have basic query regarding Windows Scripting on Windows 7 command prompt.

there is batch like below.
<Start of file>
@ECHO off
FOR /F "usebackq eol=; delims=" %%i  IN ("file.sql") DO (

       IF NOT "%%i" EQU "" ECHO %%i >> test.txt
)

ECHO;
ECHO ********************************
pause
<end of file>

input file.sql has multiple blank lines, which will resulted to see lines like this.
ECHO is off.

I would like to avoid this case, would somebody please help to advice how I can simply skip blank line so that "ECHO is off." will not be printed?
sleepinglukeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITCommented:
If %%i begins with a SPACE character, that would happen.
0
sleepinglukeAuthor Commented:
thanks, how can I skip that case, a space in addition to blank within this windows script?
0
NVITCommented:
@ECHO off
 FOR /F "usebackq eol=; delims=" %%i  IN ("file.sql") DO (
        IF NOT "%%i" EQU "" IF NOT "%%i" EQU " " ECHO %%i >> test.txt
 )

Open in new window

0
oBdACommented:
Simple fix: use "echo.%%i" (note the dot instead of a space after the "echo").
In addition, you're adding a space at the end of each line with the "ECHO %%i >> test.txt" (and you should probably delete test.txt at the beginning of the script).
Try it like this:
@ECHO off
FOR /F "usebackq eol=; delims=" %%i  IN ("file.sql") DO (
	>>test.txt ECHO.%%i
)
ECHO;
ECHO ********************************
pause

Open in new window


And on a side note:
IF NOT "%%i" EQU ""
is superfluous in a "for /f" loop; "for /f" skips empty lines, those never enter the loop body.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sleepinglukeAuthor Commented:
Dear NewVillageIT,  oBdA

Thank you very much to both for support! It works perfectly!!

Thanks Regards
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Shell Scripting

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.