echo new line

echo 'hello \n there'

doesnt appear as

hello
there

Why ?
PradeepYadhavAsked:
Who is Participating?
 
Harisha M GCommented:
echo hello & echo there
0
 
Steve KnightIT ConsultancyCommented:
Because \n isn't an option in batch programming... as had been said combine two echo commands in one line with an ampersand or just put it on two lines...

echo hello
echo there

echo.    gives a blank line btw

Is there a bigger issue you are dealing with here or does that cover it?

Steve
0
 
PradeepYadhavAuthor Commented:
I am trying to write in to a file with new lines
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

 
PradeepYadhavAuthor Commented:
echo 'hello blank line there' > file
0
 
PradeepYadhavAuthor Commented:
echo 'hello newline there' > file
0
 
PradeepYadhavAuthor Commented:
ouput

hello
there
0
 
Steve KnightIT ConsultancyCommented:
OK You just need to do
echo hello > file.txt
echo there >> file.txt

>> appends
> creates new

hth

Steve
0
 
PradeepYadhavAuthor Commented:
right thats what I am doing. I wanted to execute one echo command to fill a file with line breaks.. Thats not possible. Thank U.
0
 
Steve KnightIT ConsultancyCommented:
You can't do that.  You can easily do a loop though.

del file.txt 2>NUL
for /l %a in (1,1,50) do echo. >> file.txt

which will delete the file then add 50 new lines.

Steve
0
 
Steve KnightIT ConsultancyCommented:
Pradeep, are you still there?  You were very quick to respond before but then went quiet?

Steve
0
 
For-SoftCommented:
ECHO command always generates one full line.
In other words, a line break is put at the end of text displayed by ECHO command, always.

ECHO. - gives an emty line (a line break)

It is possible to do much more if an ANSI.SYS driver is installed. ANSI graphics enables ESC commands capable of:
- cursor moving in every direction,
- cursor positioning in desired coordinates
- curson position storing and going back to the stored position
- removing lines from the screen
- changing character colors and attributes
- clearing the screen
and more.

But, the ANSI commands are screen related, and will not work if redirecter to a file, as far as I know.
0
 
SunBowCommented:
ansi.sys was cool
0
 
SunBowCommented:
Q> echo 'hello \n there'
> doesnt appear as desired, why?

The \n is from c language, not from microsoft batch commands
0
 
CaudaxCommented:
ANSI.SYS is cool but the affiliated (F3 = DELTREE /Y C:\WINDOWS\) ANSIBOMB wasn't as appreciated.
0
 
Steve KnightIT ConsultancyCommented:
Doh, now you've restarted the 21 days to cleanup clock again...
0
 
Steve KnightIT ConsultancyCommented:
OK, or Accept me... since we found out he wanted to write newlines to a file
0
 
sirbountyCommented:
Thought about that, but in truth - the opening question was how to write two outputs with a single command...
0
 
Steve KnightIT ConsultancyCommented:
Not the end of the world either way, eh!

Perhaps I should have added a smiley on the end of that last comment

Steve
0
 
sirbountyCommented:
It wouldn't have helped.
Cash is always good though...lol
0
 
Steve KnightIT ConsultancyCommented:
Hmm, pounds for points, sounds good.... if only it worked the other way around we'd be rich ;-)
Off to bed now!

Steve
0
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.

All Courses

From novice to tech pro — start learning today.