1

Possible Duplicate:
How can you echo a newline in batch files?

I'm wondering if i could have some help with making line breaks in an ouput .txt file made using a batch file.
Here's the beginning of my script, so you might see better what i mean:

@echo OFF
type NUL > newfile.txt
ECHO Hello, world. I am currently asking a question. > newfile.txt

I want the text to be output into the newfile.txt file looking like this:

Hello, world.
I am currently asking a question.

I have tried searching around alot, trying different suggestions that use & and ^ and ECHO and ECHO. and $'\r' but i haven't gotten anything to work. Any help would be much appreciated.

Community
  • 1
  • 1
user1785261
  • 45
  • 1
  • 2
  • 10
  • The same question is answered in this post. [Inserting a carriage return in Windows batch files][1] [1]: http://stackoverflow.com/questions/132799/how-can-you-echo-a-newline-in-batch-files – seaEagle Oct 30 '12 at 11:19
  • found this. [http://stackoverflow.com/questions/132799/how-can-you-echo-a-newline-in-batch-files][1] Maybe it will be to your help. [1]: http://stackoverflow.com/questions/132799/how-can-you-echo-a-newline-in-batch-files – Johan Brännmar Oct 30 '12 at 11:28

2 Answers2

3

You can embedd linefeeds in your echo.

The empty line is required here

@echo off
echo Hello, world.^

I am currently asking a question. >newfile.txt

Or for better optics you can move the linefeed into a variable

@echo off
setlocal EnableDelayedExpansion
set LF=^


rem Two empty lines are required
echo Hello, world.!LF!I am currently asking a question. >newfile.txt
jeb
  • 78,592
  • 17
  • 171
  • 225
2

One way;

@(
echo Hello, world
echo I am currently asking a question
echo I like cake.
) > newfile.txt
Alex K.
  • 171,639
  • 30
  • 264
  • 288