簡體   English   中英

cmd.exe, append 文本在新行

[英]cmd.exe, append text on new line

我正在嘗試編寫腳本在多台 windows 機器上的文件中附加一行。 命令echo text >> file.txt不會將單詞text放在換行符上,而是放在最后一行。 我似乎無法讓 \n 或 \r 在 windows 上使用 echo。 幫助!

我假設file.txt中的最后一行沒有被換行符終止,所以你可以明確地 append 這樣:

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 個字符或字節。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM