views:

64

answers:

3

how to append an empty line in text file using command line

 echo hi >a.txt
    echo >>a.txt
    echo arun >>a.txt 

here the out put comes as

hi 
echo on 
arun 

so how could i append a empty line ..i want it to be like .

hi 

arun

when i added this line on code @echo off it said echo off .how can it be done

+3  A: 

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).

Michael Myers
thank for ur quick response.
Arunachalam
Hmmm, that didn't work for me in ubuntu, recognized echo. as an unfound command.
Tchalvak
@Tchalvak: This is a Windows question as far as we can tell from the clues in the question.
Michael Myers
Ah, Fair enough. What an annoying implementation of the command.
Tchalvak
There 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.
Joey
Thanks, @Johannes. I didn't look closely enough.
Michael Myers
+1  A: 

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

jjclarkson
pity upvote, not sure why the downvote
BlueRaja - Danny Pflughoeft
A: 

whats wrong with simple

echo hi\n >> a.txt

?

Vishal Seth