congdantoancau

Find and replace

Nov 26th, 2021 (edited)
822
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Batch 0.50 KB | None | 0 0
  1. :: https://stackoverflow.com/questions/23075953/batch-script-to-find-and-replace-a-string-in-text-file-without-creating-an-extra/23076141
  2.  
  3. @echo off
  4.     setlocal enableextensions disabledelayedexpansion
  5.  
  6.     set "search=%1"
  7.     set "replace=%2"
  8.  
  9.     set "textFile=file.txt"
  10.  
  11.     for /f "delims=" %%i in ('type "%textFile%" ^& break ^> "%textFile%" ') do (
  12.         set "line=%%i"
  13.         setlocal enabledelayedexpansion
  14.         >>"%textFile%" echo(!line:%search%=%replace%!
  15.         endlocal
  16.     )
Advertisement
Add Comment
Please, Sign In to add comment