简体   繁体   中英

How to append an empty line in a text file using the command line?

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?

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

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

它应该可以简单

echo hi\n >> a.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM