find and delete a word in a text by batch file

2019-09-08 05:30发布

Hi all I want to find and delete some word by a batch file i tried this:

@Echo OFF
REM Set These Variables
SET "InFile=Unloaded.txt"
SET "OutFile=NowLoaded.txt"
SET "Replace=%r%"
SET "ReplaceWith=  "

REM Get Total Lines Number [including empty lines]
FOR /F %%A IN ('TYPE "%InFile%"^|find /v /c ""') DO SET "Till=%%A"

REM Create The OutFile with changes
SETLOCAL EnableDelayedExpansion
<"!InFile!" (
  FOR /L %%a IN (1 1 0) DO SET /p "="
  FOR /L %%A IN (1 1 %Till%) DO (
    SET "line="
    SET /P "line="
    IF "!line!x" == "x" ( Echo.
   ) ELSE ( Echo !line:%Replace%=%ReplaceWith%!)
  )
)>>"%OutFile%"

ENDLOCAL

but in out put instead of delete that says Echo Is Off. please help me thanks.

1条回答
姐就是有狂的资本
2楼-- · 2019-09-08 06:00

Take a look at replacer.bat.You can use it by like this to delete a word in text file:

call replacer.bat text.txt "word" ""

More powerful solutions are JREPL.bat and FindRepl.bat.

查看更多
登录 后发表回答