Batch / Find And Edit Lines in TXT file

后端 未结 8 1591
陌清茗
陌清茗 2020-11-28 06:30

I want to create a batch while which finds specific lines in a batch file and are able to edit these lines.

Example:

//TXT FILE//

ex1
ex2
ex3         


        
8条回答
  •  没有蜡笔的小新
    2020-11-28 07:10

    @echo off
    set "replace=something"
    set "replaced=different"
    
    set "source=Source.txt"
    set "target=Target.txt"
    
    setlocal enableDelayedExpansion
    (
       for /F "tokens=1* delims=:" %%a in ('findstr /N "^" %source%') do (
          set "line=%%b"
          if defined line set "line=!line:%replace%=%replaced%!"
          echo(!line!
       )
    ) > %target%
    endlocal
    

    Source. Hoping it will help some one.

提交回复
热议问题