使用任何Windows命令,你怎么能做到这一点?
e.g。删除file.txt中的第2行
答案 0 :(得分:1)
是的,可以在BAT脚本中完成。
阅读HELP FOR
和HELP SET
然后尝试此
@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
)
答案 1 :(得分:0)
嗨我相信用命令行无法完成,这是一项复杂的要求。
您想更详细地解释一下您的任务吗?
这是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