How do I delete the last line of a text file using the echo command in windows?
如何使用windows中的echo命令删除文本文件的最后一行?
2 个解决方案
#1
Echo only has 2 uses:
Echo只有2种用途:
ECHO [ON | OFF]
ECHO [message]ECHO [ON | OFF] ECHO [留言]
You can overwrite a file completely using a redirect
您可以使用重定向完全覆盖文件
ECHO Testing > a.txt
Or you can append to a file using an append redirect
或者,您可以使用追加重定向追加到文件
ECHO Testing >> a.txt
Or you can write a new line
或者你可以写一个新的一行
ECHO.
But you can't use it to remove the last line
但你不能用它来删除最后一行
#2
Have a look for a 'tail' command/equivalent (plenty on google depending on OS version).
寻找一个'尾'命令/等效(谷歌很多,取决于操作系统版本)。
then
copy oldfile tempfile
复制oldfile tempfile
tail -1 > oldfile
tail -1> oldfile
Regards Michael.
#1
Echo only has 2 uses:
Echo只有2种用途:
ECHO [ON | OFF]
ECHO [message]ECHO [ON | OFF] ECHO [留言]
You can overwrite a file completely using a redirect
您可以使用重定向完全覆盖文件
ECHO Testing > a.txt
Or you can append to a file using an append redirect
或者,您可以使用追加重定向追加到文件
ECHO Testing >> a.txt
Or you can write a new line
或者你可以写一个新的一行
ECHO.
But you can't use it to remove the last line
但你不能用它来删除最后一行
#2
Have a look for a 'tail' command/equivalent (plenty on google depending on OS version).
寻找一个'尾'命令/等效(谷歌很多,取决于操作系统版本)。
then
copy oldfile tempfile
复制oldfile tempfile
tail -1 > oldfile
tail -1> oldfile
Regards Michael.