Reputation: 6037
How do I append an empty line in a text file using the command line?
echo hi >a.txt
echo >>a.txt
echo arun >>a.txt
Here the output comes as:
hi
echo on
arun
So how could I append an empty line? I want it to be like this:
hi
arun
When I added this line on code @echo off
, it said echo off
. How can it be done?
Upvotes: 21
Views: 47176
Reputation: 11
I've battling with this for a while here's a tip of how i fixed it:
On you batch, put "echo(>> textfile.txt" (without quotation) without spaces between the echo command and the redirector or you'll get a line with a space. Not ideal if you're compiling a file to paste somewhere like excel and need the cell to be empty like i did for whatever reason.
Hope it helps.
Upvotes: 1
Reputation: 191905
In the Windows command prompt, try:
echo.>> a.txt
Note that there is no space between echo
and .
; if there is one, it will output a dot. There is also no space between the .
and the >>
; anything in between would be output to the file, even whitespace characters.
See the Microsoft documentation for echo
.
If this were in bash, your first try would have been correct:
echo >> a.txt
But in Windows, the unqualified echo
command tests whether there is a command prompt or not (echo off
turns the prompt off and echo on
turns it back on).
Upvotes: 37
Reputation: 5954
At Windows Prompt:
echo. >> a.txt
At BASH Prompt:
echo >> a.txt
(Echo by default sends a trailing newline)
-n do not output the trailing newline
Upvotes: 6