如何从批处理文件输出中插入换行符?

我想做的事情是:

echo hello\nworld

这将输出:

hello
world

当前回答

如果你需要把结果放到一个文件中,你可以使用:

(echo a & echo: & echo b) > file_containing_multiple_lines.txt

其他回答

如果你需要把结果放到一个文件中,你可以使用:

(echo a & echo: & echo b) > file_containing_multiple_lines.txt

Use:

echo hello
echo:
echo world

有一个标准的功能echo:在cmd/bat-files中写入空行,这模拟了cmd-output中的新行:

@echo off
echo line1
echo:
echo line2

or

@echo line1 & echo: & echo line2

上面引用的cmd-file输出:

line1

line2

Ken和Jeb的解决方案效果很好。

但是新行只生成一个LF字符,我需要CRLF字符(Windows版本)。

为此,在脚本的末尾,我已经将LF转换为CRLF。

例子:

TYPE file.txt | FIND "" /V > file_win.txt
del file.txt
rename file_win.txt file.txt

为什么不使用子字符串/替换空格来echo;?

set "_line=hello world"
echo\%_line: =&echo;%

结果:

hello
world

或者,将\n替换为echo;

set "_line=hello\nworld"
echo\%_line:\n=&echo;%