Hi All.
Thanking you in advance:
I am looking for a way to resolve a hostname and then append an ini file with the ip address. The problem that I am experiencing is that in the ini file, there are multiple Ip addresses and I only want to update the IPAddress line under one of the fifty headings. Here is an example of the ini file which contains 50 exact listings like below with the only point of reference being the [Headind] on top of each section.
[Estacion 1]
Version=1
Channel=SOCKET
Cpu=0
Station=1
AutoStation=0
Retry=3
DontClose=0
PguMode=0
PhoneNumber=
CountryCode=0
AreaCode=0
Location=
UseDialing=0
DeviceName=
IPAddress=189.14.80.10
FdlStation=0
Cheers
FiZz
Lookup and append ini file
Moderator: DosItHelp
Re: Lookup and append ini file
Are there any blank lines in the file that you need to retain?
You can read the INI file and write to a temp file - comparing each line for the heading that you need to change.
When the heading is located, set an environment variable so that the next time the
IPAddress=
is located then it will modify the IP address - and clear the variable so it doesn't change any further lines.
You can read the INI file and write to a temp file - comparing each line for the heading that you need to change.
When the heading is located, set an environment variable so that the next time the
IPAddress=
is located then it will modify the IP address - and clear the variable so it doesn't change any further lines.
Re: Lookup and append ini file
Thanks for the speedy reply
There are not blank lines whatsoever.
Please could you give me an example of how to compare and set the environment variable.
There are not blank lines whatsoever.
Please could you give me an example of how to compare and set the environment variable.
Re: Lookup and append ini file
This does the job here:
Code: Select all
@echo off
setlocal enabledelayedexpansion
set ip=111.222.333.444
set "found="
del file.new 2>nul
for /f "delims=" %%a in (file.ini) do (
set "line=%%a"
if "%%a"=="[Estacion 1]" set found=1
if not defined found (>>file.new echo %%a)
if defined found (
if "!line:~0,10!"=="IPAddress=" (>>file.new echo IPAddress=%ip%&set "found=") else (>>file.new echo %%a)
)
)
pause
Re: Lookup and append ini file
Perfection.
Thank You for your assistance.
Thank You for your assistance.