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

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

qq41447815 回答:cmd.exe,在新行上附加文本

我假设file.txt中的最后一行没有被换行符终止,因此您可以显式地添加以下内容:

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

如果file.txt可能会或可能不会被换行符终止,则可以使用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

请注意,find将行长度限制为4095个字符或字节。

本文链接:https://www.f2er.com/3156323.html

大家都在问