计算机技术

使用批处理删除HOSTS文件中含有特定字符的某行

@echo off
set Row=
set Str=
set "Xstr=1993"
set "Files=C:WindowsSystem32driversetchosts"
set "OutputFiles=C:WindowsSystem32driversetc$"
if exist "%Files%" (
setlocal enabledelayedexpansion
for /f "delims=" %%a in (%Files%) do (
    set/a Row+=1 & set "Str=%%a"
    ((echo !Str! | findstr /i "!Xstr!">nul) && (
        echo Found target text.(发现目标文字!)
    )) || (
        echo !Str!>>!OutputFiles!
    )
))
move !OutputFiles! %Files%>nul 2>nul
echo Completed (执行完毕)!!
pause>nul

Related Articles

发表回复

Check Also
Close
Back to top button