views:

29605

answers:

15

How can you you insert a newline from your batch file output.

I want to do something like:

> echo hello\nworld

Which would output:

hello
world

+12  A: 

use

echo hello
echo.
echo world
Matt Lacey
Is it possible while providing a string within a single echo statement?
Brian R. Bondy
Ah. Beat me by 30 seconds. :)
Raithlin
Why do you need to do it with a single echo statement; where's the harm in having another?I assume you're not simply adding unnecessary constraints for the fun of it...
Rob
That doesn't seem any better than echo hello, echo world.
paxdiablo
That would actually output "hello, echo world" :)
Joey
+9  A: 

echo hello && echo.world

This means you could define "&& echo." as a constant for a newline.

Grimtron
Alexander Prokofyev
A: 

Either break it into multiple statements, or use printf:

kburton@indigo64:~$ echo "foo"; echo; echo "bar"
foo

bar
kburton@indigo64:~$

With printf:

kburton@indigo64:~$ printf "this\nthat\n"
this
that
kburton@indigo64:~$
Kyle Burton
A: 

I don't think MS-Dos supports new-line characters. If you want output on 2 lines use 2 echos.

echo hello echo world

Rene
+14  A: 

Here you go, create a .bat file with the following in it:

@echo off

REM Creating a Newline variable (the two blank lines are required!)
set NLM=^


set NL=^^^%NLM%%NLM%^%NLM%%NLM%
REM Example Usage:
echo There should be a newline%NL%inserted here.

echo.
pause

You should see output like the following:

There should be a newline
inserted here.

Press any key to continue . . .

You only need the code between the REM statements, obviously.

Very impressive, could you take time to explain how the line set NL=^^^%NLM%%NLM%^%NLM%%NLM%works? I can't quite get my head round it
Andy Morris
+2  A: 

When echoing something to redirect to a file, multiple echo commands will not work. I think maybe the ">>" redirector is a good choice:

echo hello > temp
echo world >> temp
Crend King
A: 

Hi All,

I have a file1.txt that has the content as A and file2.txt that has the content as B . . . . fileXX.txt that the content Z

Could some tell me how to copy contents from all the above files(random number) to another file say file_final.txt with the contents from each file separated by a new line. i.e. A B C D . . . Z

Please don't ask unrelated questions on existing questions -- make a new question instead.
Jeremy Dunck
A: 

hey thanks for the reply. This will work if i have a few files. Let's say i have a 100 of them. Any sort of "for" logic.. that reads contents from 1 file and at the end of each file's contents, "add" a new line and THEN put contents of the second file and so on and so forth?

A: 

@Kyle Burton: "Either break it into multiple statements, or use printf:"

The OP asked a question relating to MS-DOS Batch (look at the tags!) and you talked about Linux shell commands. What a dimwit!!!

Slivery
This should have been a comment, or not said at all-- use downvotes for things you disagree with -- no need to insult people.
Jeremy Dunck
A: 

there is another method besides "echo." :

echo new-line-char

the newline character is input by alt+255(type 2,5,5 while alt key is pressed. !type the num using the keypad to the right of the keyboard!)

refers http://www.computerhope.com/issues/ch000319.htm

+1  A: 

just like Grimtron suggests - here is a quick example to define it

@echo off
set newline=^& echo.
echo hello %newline%world

output

C:\>test.bat
hello
world
Xaleph
A: 

This worked for me:

(echo asdf
) >myfile.txt

It writes a file like this (please, omit the text "<--new line here!!"):

    asdf
<--new line here!!
NahuelGQ
A: 

There is a standard feature echo: in cmd/bat-files to write blank line, which emulates a new line in your cmd-output:

@echo off
@echo line1
@echo:
@echo line2

Output of cited above cmd-file:

line1

line2
macropas
A: 

echo. does not work for me on Windows XP SP1

syam
A: 

Hi All,

I need echo without newline char included.

Actually I am writting a text in to a text file using echo.

echo mydata > myfile.txt

When I open the file in the text editor...It is showing a new line (Second line) like...

mydata

(blank Line with no values.)

It is obvious that the file ends with a newline. I have to avoid that. I tried DOS2Unix tool, but no luck.

Simply, I want to remove the newline at the end of my data file using Batch commands.

Please help!

Muthukkumaran