Here is a beginning example, but you should give us more details to understand more your aim :
@echo off
setlocal enabledelayedexpansion
set "filename=c:\Work\Clients\bcg\Config\Tm1s.cfg"
for /f "usebackq tokens=2 delims==" %%i in (`findstr /r /c:"HTTPPortNumber=.*" %filename%`) do (
set "port=%%i"
set /a "newport=port+1"
set "newline=HTTPPortNumber=!newport!"
echo Found HTTPPortNumber=!port!. Incrementing to !newport!.
type %filename% | findstr /v /c:"HTTPPortNumber=.*" > tempfile.txt
echo !newline! >> tempfile.txt
move /y tempfile.txt %filename% > nul
)
echo Done.
pause
This script uses the findstr
command to search for the line containing HTTPPortNumber=
in the specified file.
The line is then processed using the for /f
loop, where usebackq tokens=2 delims==
is used to parse the line and extract the second token (the port number).
The port number is then incremented by 1 and saved back to the file by creating a temporary file with the updated line and then moving the temporary file back to the original file.
Edit : Powershell Solution
$filename = 'c:\Work\Clients\bcg\Config\Tm1s.cfg'
$fileContent = Get-Content $filename
$newContent = ''
foreach ($line in $fileContent) {
if ($line -match 'HTTPPortNumber=\d+') {
$port = [int] ($line -replace 'HTTPPortNumber=(\d+)', '$1')
$newport = $port + 1
Write-Output "Found HTTPPortNumber=$port. Incrementing to $newport."
$newContent += "HTTPPortNumber=$newport" + [Environment]::NewLine
} else {
$newContent += $line + [Environment]::NewLine
}
}
Set-Content $filename $newContent
Write-Output 'Done.'
This Powershell script will search for the line HTTPPortNumber=####
in the file c:\Work\Clients\bcg\Config\Tm1s.cfg
and increment the value of #### by 1.
The updated value will be saved back to the same file.