如何在使用批处理文件创建的输出.txt文件中进行换行。

35 浏览
0 Comments

如何在使用批处理文件创建的输出.txt文件中进行换行。

这个问题已经有了答案

可能与此重复:

如何在批处理文件中回显换行符?

我想知道如何在使用批处理文件创建的输出.txt文件中插入换行符。

这是我的脚本开头,你可能看得更清楚:

@echo OFF
type NUL > newfile.txt
ECHO Hello, world. I am currently asking a question. > newfile.txt

我希望文本输出到newfile.txt文件中看起来像这样:

Hello, world.
I am currently asking a question.

我已经试过很多搜索,尝试了不同的建议,使用&^ECHOECHO.$\'\\r\',但我什么都没做成功。任何帮助将不胜感激。

admin 更改状态以发布 2023年5月22日
0
0 Comments

一种方法;

@(
echo Hello, world
echo I am currently asking a question
echo I like cake.
) > newfile.txt

0
0 Comments

您可以在回显中嵌入换行符。

这里需要一个空行

@echo off
echo Hello, world.^
I am currently asking a question. >newfile.txt

或者为了更好的视觉效果,您可以将换行符放入变量中

@echo off
setlocal EnableDelayedExpansion
set LF=^
rem Two empty lines are required
echo Hello, world.!LF!I am currently asking a question. >newfile.txt

0