cmd.exe,在新行上附加文本

问题描述 投票:0回答:1

我正在尝试编写脚本,将行添加到多台Windows计算机上的文件中。命令echo text >> file.txt不会将单词text放在换行符上,而是放在最后一行。我似乎无法在Windows上使用\ n或\ r处理回声。救命!

windows cmd echo
1个回答
0
投票

我假设file.txt中的最后一行没有被换行符终止,所以您可以显式附加这样的内容:

rem // Append line-break plus text:
(echo/&echo text) >> file.txt

如果file.txt可能会或可能不会以换行符终止,则可以使用find

find

请注意,rem // Use `find` to force a final line-break, then append text and write to temporary file: (find /V "" < file.txt & echo text) > file.txt.tmp rem // Move temporary file onto original one: move /Y file.txt.tmp file.txt 将行长度限制为4095个字符或字节。

© www.soinside.com 2019 - 2024. All rights reserved.