批次:从文本文件的末尾删除换行? [英] Batch: delete line feed from end of text file?

查看:198
本文介绍了批次:从文本文件的末尾删除换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个txt文件,我需要摆脱的最后一行饲料。
看着在十六进制编辑器文件显示0D 0A结尾。

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.

我已经看过线程如何使用批处理文件但这并没有帮助。
我曾尝试复制源目标/ B 这也于事无补。

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.

不幸的是我不能使用Java或任何第三方工具,我需要使用一个批处理文件。

Unfortunately I can't use Java or any third party tools, I need to use a batch file.

有没有人有一个想法如何,最后才能摆脱换行吗?

Does anyone have an idea how to get rid of that line feed at the end?

非常感谢和问候,
彼得

Thank you very much and best regards, Peter

推荐答案

使用批处理这应该工作。

Using batch this should work.

@echo off
setlocal DisableDelayedExpansion
set "firstLineReady="
(
    for /F "eol=$ delims=" %%a in (myFile.txt) DO (
        if defined firstLineReady (echo()
        set "firstLineReady=1"
        <nul set /p "=%%a"
    )
) > out.txt

这会将所有的线条和追加到每行一个CR / LF,而不是到最后一个

It copies all lines and append to each line a CR/LF, but not to the last one

这篇关于批次:从文本文件的末尾删除换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆