Windows Batch,如何删除第一行和最后一行并另存为新的文本文件 [英] Windows Batch, how to remove first line and last line and save as a new text file

查看:61
本文介绍了Windows Batch,如何删除第一行和最后一行并另存为新的文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

text1.txt

text1.txt

20150716
aaaa
bbbb
cccc
dddd
END

我想删除20150716,然后整个文本将上移1行并删除最后一个特定的字符串"END".最后,另存为名为text1_copy.txt的新文件.然后,文件变为:

I would like to remove 20150716, then the whole text will move up by 1 line and remove the last particular string "END". Finally, save as a new file called text1_copy.txt. Then, file becomes:

aaaa
bbbb
cccc
dddd

有什么想法吗?谢谢.

推荐答案

这只是跳过第一行,而不写最后一行.

This just skips the first line and does not write the last one.

@echo off
    setlocal enableextensions disabledelayedexpansion

    for %%a in ("text1.txt") do > "%%~dpna_copy%%~xa" (
        set "line="
        for /f "skip=1 tokens=* delims=0123456789" %%a in ('
            findstr /n /r "^" "%%a"
        ') do (
            if defined line (
                setlocal enabledelayedexpansion
                echo(!line:~1!
                endlocal
            )
            set "line=%%a"
        )
    )

这篇关于Windows Batch,如何删除第一行和最后一行并另存为新的文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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