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