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?
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.
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.
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.
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.
( echo Here is my first line echo Here is my second line echo Here is my third line )>"myNewTextFile.txt" pause
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With