find and delete a word in a text by batch file

梦想与她 提交于 2019-12-13 07:52:38

问题


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:


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.



来源:https://stackoverflow.com/questions/32494947/find-and-delete-a-word-in-a-text-by-batch-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!