How to append an empty line in a text file using the command line?
Solution 1
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).
Solution 2
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
Comments
-
Arunachalam almost 2 years
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 saidecho off
. How can it be done? -
Kzqai about 14 yearsHmmm, that didn't work for me in ubuntu, recognized echo. as an unfound command.
-
palantus about 14 years@Tchalvak: This is a Windows question as far as we can tell from the clues in the question.
-
Kzqai about 14 yearsAh, Fair enough. What an annoying implementation of the command.
-
Rich about 14 yearsThere shouldn't be a space between the dot and the redirection operator. Otherwise this will output a space followed by a line break. For some definitions of “empty line” that's not exactly empty.
-
palantus about 14 yearsThanks, @Johannes. I didn't look closely enough.
-
Inversus over 11 yearsThat will output the string literal "\n" to the file
-
Duncan Howe about 2 yearsSome 12 years later, I found that in a batch file, with
@echo OFF
doing this writesECHO IS OFF
rather than a blank line. If you add a space between the dot and the double chevron then it works as expected (i.e.echo. >> file.txt
)