[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 970
  • Last Modified:

suppressing echo is off msg

Stupid question, but why would this piece id code say Echo is off. in the output. It puts out the required output then also says echo is offin the next line...I just see echo called once?? Could someone help me get rid of 'echo is off'

Thanks

@echo off
set InputFile=in.txt
set OutputFile=out.txt
if exist "%OutputFile%" del "%OutputFile%"
for /f "skip=3 delims=" %%a in ('type "%InputFile%"') do >>"%OutputFile%" echo %%a
back to top
0
chetan1981
Asked:
chetan1981
3 Solutions
 
Lee W, MVPTechnology and Business Process AdvisorCommented:
If %%a = nothing then all you have there is "echo".

0
 
chetan1981Author Commented:
Thx leew, so how do I make it stop before it gets to where %%a is nothing
0
 
Brian PringleSystems Analyst II, SCM, ERPCommented:
Your "DO" command should actually do something.  Are you trying to echo %%a TO %OutputFile%?
0
Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
chetan1981Author Commented:
yeah, just adding lines from one file to another
0
 
Brian PringleSystems Analyst II, SCM, ERPCommented:
then it should be DO echo %%a >> %OutputFile%
0
 
ghostdog74Commented:
it works fine for me. I am using win XP cmd.
0
 
chetan1981Author Commented:
I tried that....it still says echo is off
Thanks
0
 
Brian PringleSystems Analyst II, SCM, ERPCommented:
rem out that line with the FOR loop and replace it with

echo %%a

What is the output there?
0
 
Brian PringleSystems Analyst II, SCM, ERPCommented:
sorry.  won't work.  rem it out and make a copy of it, but don't include the >> %OutputFile%.

What is the output?
0
 
chetan1981Author Commented:
No output, in case it helps I am just copying line #4, the way it works now is that it skips the first 3 lines and gets the 4th line.  Maybe instead of the for loop I could just get line#4 ?

Thanks for your patience..
0
 
Brian PringleSystems Analyst II, SCM, ERPCommented:
Try removing the quotes from around %InputFile% in the FOR loop.  They would cause it to read that as a string instead of a variable.
0
 
chetan1981Author Commented:
here's the outputat the console

C:\Tmp\sql_check>set InputFile=MSSQLD004.txt

C:\Tmp\sql_check>set OutputFile=MSSQLD001.txt

C:\Tmp\sql_check>if exist "MSSQLD001.txt" del "MSSQLD001.txt"

C:\Tmp\sql_check>rem for /f "skip=3 delims=" %a in ('type "MSSQLD004.txt"')
 do echo %a>>MSSQLD001.txt

C:\Tmp\sql_check>for /F "skip=3 delims=" %a in ('type "MSSQLD004.txt"') do
echo %a

C:\Tmp\sql_check>rem type MSSQL.txt >> data1.txt

C:\Tmp\sql_check>
0
 
Brian PringleSystems Analyst II, SCM, ERPCommented:
Did you remove the quotes around the ('type "%InputFile%"')?  Your line should be as follows.

for /f "skip=3 delims=" %%a in ('type %InputFile%') do echo %%a >> %OutputFile%
0
 
Steve KnightIT ConsultancyCommented:
Try adding & goto :eof to the end to exit the loop after the fourth line has been output:

for /f "skip=3 delims=" %%a in ('type "%InputFile%"') do >>"%OutputFile%" echo %%a & goto :eof
0
 
oBdACommented:
That can be caused by a line that only contains spaces. Try to put a single . between the echo and the %%a:

@echo off
set InputFile=in.txt
set OutputFile=out.txt
if exist "%OutputFile%" del "%OutputFile%"
for /f "skip=3 delims=" %%a in ('type "%InputFile%"') do >>"%OutputFile%" echo.%%a

Or, if you only want the fourth line, try this:
@echo off
set InputFile=in.txt
set OutputFile=out.txt
set GetLineNumber=4
if exist "%OutputFile%" del "%OutputFile%"
for /f "tokens=1* delims=[]" %%a in ('type "%InputFile%" ^| find /v /n ""') do if "%%a"=="%GetLineNumber%" >>"%OutputFile%" echo.%%b


btpringle,
the "for /f" command is running the *command* 'type "%InputFile%"' (and processing its output), not trying to read directly from the file "%InputFile%".
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now