- 1 year ago
find number in file iterate and replace windows .bat
Comment
1 / 1
Here's an example of a Windows batch script that finds and replaces numbers in a file using a loop:
bat@echo off
setlocal EnableDelayedExpansion
set inputFile=input.txt
set outputFile=output.txt
set findNumber=10
set replaceNumber=20
if exist "%outputFile%" del "%outputFile%"
for /f "tokens=*" %%a in (%inputFile%) do (
set line=%%a
set modifiedLine=!line:%findNumber%=%replaceNumber%!
echo !modifiedLine!>> %outputFile%
)
echo Done.
In this example, the script searches for the number 10
in the input.txt
file and replaces it with the number 20
. The modified lines are written to a new file called output.txt
.
You can modify the values of inputFile
, outputFile
, findNumber
, and replaceNumber
to match your specific needs.