简体   繁体   English

如何使用 windows 中的 echo 命令删除文本文件的最后一行?

[英]How do I delete the last line of a text file using the echo command in windows?

How do I delete the last line of a text file using the echo command in windows?如何使用 windows 中的 echo 命令删除文本文件的最后一行?

Echo only has 2 uses: Echo 只有两种用途:

ECHO [ON |回声 [开 | OFF]离开]
ECHO [message]回声 [消息]

You can overwrite a file completely using a redirect您可以使用重定向完全覆盖文件

ECHO Testing > a.txt

Or you can append to a file using an append redirect或者您可以使用 append 重定向 append 到文件

ECHO Testing >> a.txt

Or you can write a new line或者你可以写一个新行

ECHO.

But you can't use it to remove the last line但是你不能用它来删除最后一行

Have a look for a 'tail' command/equivalent (plenty on google depending on OS version).寻找一个'tail'命令/等效项(根据操作系统版本在谷歌上有很多)。

then然后

copy oldfile tempfile复制旧文件临时文件

tail -1 > oldfile尾 -1 > 旧文件

Regards Michael.问候迈克尔。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM