Batch file append text new line

A simple but useful question!

To append text to a file and add a new line in a batch file, you can use the following syntax:

echo. >> file.txt
echo Your new text here >> file.txt

Here's what's happening:

So, when you run these two lines, the file file.txt will be created or updated with the following contents:

Your new text here

If you want to add multiple lines of text, you can repeat the echo command with the desired text:

echo. >> file.txt
echo Your new text here >> file.txt
echo Another line of text >> file.txt

This will result in the following contents in the file:

Your new text here
Another line of text

Note that if you want to add a literal newline character (\n) to the file, you can use the following syntax:

echo Your new text here^& >> file.txt

The ^& is an escape sequence that tells the batch file to treat the newline character as a literal character instead of a command separator.