[CMD] Replace string bằng command line trên windows
Hướng dẫn tạo batch file replace string trên windows
Lệnh mẫu
@echo off &setlocal
set "search=oldstring"
set "replace=newstring"
set "textfile=duongdanfile.txt"
set "newfile=duongdannewfile.txt"
(for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
del %textfile%
ren %newfile% %textfile%
set "search=oldstring"
set "replace=newstring"
set "textfile=duongdanfile.txt"
set "newfile=duongdannewfile.txt"
(for /f "delims=" %%i in (%textfile%) do (
set "line=%%i"
setlocal enabledelayedexpansion
set "line=!line:%search%=%replace%!"
echo(!line!
endlocal
))>"%newfile%"
del %textfile%
ren %newfile% %textfile%
Chúc các bạn thành công
Bình luận
Gửi