windows 如何使用命令行在文本文件中附加一个空行?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2554865/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to append an empty line in a text file using the command line?
提问by Arunachalam
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?
当我在代码上添加这一行时@echo off
,它说echo off
。怎么做到呢?
回答by Michael Myers
In the Windows command prompt, try:
在 Windows 命令提示符下,尝试:
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.
请注意,echo
和之间没有空格.
;如果有,它会输出一个点。.
和之间也没有空格>>
;中间的任何内容都将输出到文件中,甚至是空白字符。
See the Microsoft documentation for echo
.
If this were in bash, your first try would have been correct:
如果这是在 bash 中,您的第一次尝试将是正确的:
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).
但是在 Windows 中,unqualifiedecho
命令测试是否有命令提示符(echo off
关闭提示符并echo on
重新打开)。
回答by jjclarkson
At Windows Prompt:
在 Windows 提示符下:
echo. >> a.txt
At BASH Prompt:
在 BASH 提示符下:
echo >> a.txt
(Echo by default sends a trailing newline)
(默认情况下,echo 发送尾随换行符)
-n do not output the trailing newline
-n 不输出尾随换行符
回答by Vishal Seth
It should be possible with a simple
应该可以通过一个简单的
echo hi\n >> a.txt