如何删除文本文件中的特定行(Windows)

如何删除文本文件中的特定行(Windows),windows,batch-file,cmd,Windows,Batch File,Cmd,使用任何windows命令,您如何实现这一点 e、 g.删除file.txt中的第2行。嗨,我认为这不能用命令行来完成,这是一种复杂的要求 你想更详细地解释你的任务吗 下面是一个c语言的代码片段,可以帮助您 string filePath = @"c:\temp\test.txt"; string line; string NewText = string.Empty; if (File.Exists( filePath ))

使用任何windows命令,您如何实现这一点


e、 g.删除file.txt中的第2行。嗨,我认为这不能用命令行来完成,这是一种复杂的要求

你想更详细地解释你的任务吗

下面是一个c语言的代码片段,可以帮助您

        string filePath = @"c:\temp\test.txt";
        string line;
        string NewText = string.Empty;

        if (File.Exists( filePath ))
        {
            StreamReader file = null;

            int linecounter = 0;

            file = new StreamReader( filePath );
            while ((line = file.ReadLine()) != null)
            {
                if(linecounter==1)
                {
                     linecounter ++;
                     continue;
                }


                linecounter ++;
            }
           //then save the new text in a file or overwrite your current file

是的,它可以在BAT脚本中完成

请阅读
的帮助和
帮助设置
,然后重试此操作

@echo off
setlocal enabledelayedexpansion
set /a count=0
for /f "tokens=*" %%a in (t.txt) do (
 set /a count=count+1
 if /i !count! NEQ 2 echo %%a
)