Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Echo string to .txt file with multiple lines - with Windows Batch file

I am attempting to create a Windows Batch File that creates a .txt with mulitple lines. I've tried several solutions to insert a line break in the string but no avail. There are other similar questions/answers but none of them address putting the entire string into a text file.

My batch file currently reads:

echo Here is my first line Here is my second line > myNewTextFile.txt pause 

my goal is to have the text file read:

Here is my first line Here is my second line 

Obviously, this does not work currently, but wondering if anyone knows how to make this happen in a simple fashion?

like image 788
Linuxmint Avatar asked May 07 '14 23:05

Linuxmint


People also ask

How do I echo multiple lines in Windows?

To display a message that is several lines long without displaying any commands, you can include several echo <message> commands after the echo off command in your batch program. After echo is turned off, the command prompt doesn't appear in the Command Prompt window. To display the command prompt, type echo on.

How do I echo multiple lines in a text file?

To add multiple lines to a file with echo, use the -e option and separate each line with \n. When you use the -e option, it tells echo to evaluate backslash characters such as \n for new line. If you cat the file, you will realize that each entry is added on a new line immediately after the existing content.

What is @echo off in batch script?

batch-file Echo @Echo off @echo off prevents the prompt and contents of the batch file from being displayed, so that only the output is visible. The @ makes the output of the echo off command hidden as well.

What is %% in a batch file?

Use double percent signs ( %% ) to carry out the for command within a batch file. Variables are case sensitive, and they must be represented with an alphabetical value such as %a, %b, or %c. ( <set> ) Required. Specifies one or more files, directories, or text strings, or a range of values on which to run the command.


1 Answers

( echo Here is my first line echo Here is my second line echo Here is my third line )>"myNewTextFile.txt" pause 
like image 58
Endoro Avatar answered Oct 16 '22 06:10

Endoro