批处理:从文本文件末尾删除换行符?
continue
I have a .txt file where I need to get rid of the last line feed.
Looking at the file in a HEX Editor it shows "0d 0a" at the end.
I have looked at the thread How to delete Linefeed using batch file but that did not help.
I have tried COPY source target /b
which also does not help.
Unfortunately I can't use Java or any third party tools, I need to use a batch file.
How can I get rid of that line feed at the end?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用批处理应该可以。
它复制所有行并向每一行附加 CR/LF,但不附加到最后一行
Using batch this should work.
It copies all lines and append to each line a CR/LF, but not to the last one
尝试以下代码作为起点
此批处理首先将文件复制到需要具有 8.3 名称的临时文件。
然后它准备一个调试脚本来截掉临时文件的最后两个字节。
前两条调试指令
R
和D
仅显示文件和寄存器的内容(其中重要的CX值包含文件的长度)它们可以被删除。然后,调试脚本进入汇编程序模式
A
并生成两条DEC CX
指令,将 CX 的值递减两倍。空行离开汇编模式。该脚本执行
G
两条汇编指令。然后,调试脚本将
W
写入与读取的相同内容的文件,但长度减去两个字节。最后退出Q
调试。此代码仅适用于小于 64kB 的文件。对于更大的文件,您需要扩展汇编代码,在递减 CX 递减 BX 后检查进位标志。
有关详细信息,请阅读
DEBUG /?
,然后尝试DEBUG
和?
Try the following code as an starting point
This batch, first, copies the file to a temporary file that needs to have a 8.3 name.
Then it prepares a debug script to chop off the last two bytes of the temporary file.
The first two debug instructions
R
andD
are only to show the contents of the file and the register (with the important CX value that contains the length of the file) They can be removed.Then the debug script enters assembler mode
A
and produces twoDEC CX
instructions, that decrement twice the value of CX. The blank line leaves assembler mode.The script executes
G
the two assembly instructions.Then the debug script writes
W
back to the file the same contents read, minus two bytes in length. And finally quitsQ
debug.This code only works with files smaller than 64kB. For bigger files you need to extend the assembly code, checking for carry flag after decrementing CX to decrement BX.
For more information read
DEBUG /?
and then tryDEBUG
and?