我要删除1.txt中包含1234的一行,具体怎么写?用批处理,谢谢

删除包含字符"1234"的那一行。怎么实现?
2025-03-02 01:34:09
推荐回答(2个)
回答1:

dim fso,file,path,filename,find,read,spt,str,cy,cystr,count
set fso=createobject("scripting.filesystemobject")
file="1.txt"
if instr(file,"\")>0 then
    path=left(file,instrrev(file,"\")-1)
    filename=mid(file,instrrev(file,"\")+1)
else
    filename="new_"&file
end if
find="1234"
if fso.fileexists(file)=false then msgbox "文件不存在,请填写正确路径!",64,wscript.scriptname
read=fso.opentextfile(file).readall
if len(read)>0 and instr(read,find)>0 then
    spt=split(read,vbcrlf)
    count=-1
    for each str in spt
        if instr(str,find)=0 then
            count=count+1
            redim preserve cy(count)
            cy(count)=str
        end if
    next
    cystr=join(cy,vbcrlf)
else
    msgbox "没有找到要搜索的字符!",64,wscript.scriptname
end if
if len(path)>0 then
    fso.createtextfile(path&"\"&filename).write cystr
else
    fso.createtextfile(filename).write cystr
end if
set fso=nothing
'保存为vbs类型文件
'楼上用外部程序会大大降低执行效率
'专业vbs/bat回答,手机写的,请采纳!
'vbs每秒能执行几十万次
'批处理只有一千不到,更何况用了外出程序以后那短暂的几十毫秒的等待时间
'只是说下两者区别,并不是说批处理一无是处。 
'注意要用ctrl+c不要右键复制

回答2:

@echo off
type 1.txt|find /v "1234">1.new
move /y 1.new 1.txt