Page 1 of 1

Writing a batch file to amend .ini

Posted: 01 Feb 2016 08:43
by Raindancer
Hi All,

First time poster. I hope you might be able to help me on this please? I need to write a batch to edit an ini file on a remote CPU running XP embedded.

I need to edit an ini file on one line but leave the other lines intact with no changes.

I need to edit line 2
SCHEME=3|00|0|0|

and leave the rest of the text


PrintPause=00
SCHEME=3|10|0|0|
TL_IP=xxxx|TL_PORT=xxxx|
ULOG_IP=xxxx|ULOG_PORT=xxxx|
UDP_PORT=xxxx|
TimeFromServer|TIME_PORT=xxxx|
xxxx_COMPORT=COM5|
xxxx_COMPORT=COM3|
DeclineReInitTran|
VolumeControl|
GPS_COMPORT=COM6|
MediaUDP_IP=xxxxxxxx|
MediaUDP_Port=xxxxxx|

Is anyone able to help me please :)

Re: Writing a batch file to amend .ini

Posted: 01 Feb 2016 11:18
by thefeduke
Here is a general substitution example

Code: Select all

< theFile.txt FindRepl "ACSD" "XYZ"
using an excellent tool described here:http://www.dostips.com/forum/viewtopic.php?f=3&t=4697
If you need more help specify the text to which you want it changed.
John A.

Re: Writing a batch file to amend .ini

Posted: 04 Feb 2016 03:02
by thefeduke
I missed the subtle change. Here is some code:

Code: Select all

@Echo Off
    SetLOCAL EnableDelayedExpansion
    Echo.input:
    Type Some_Old.ini
    set "1st="
   (for /F "delims=" %%a in ('Type Some_Old.ini') do (
        If /i ".%%a" EQU ".SCHEME=3|10|0|0|" Set "1st=1"
        If ".!1st!" NEQ ".1" echo %%a
    )
   )>Some_New.ini
    Echo.
    >>Some_New.ini Echo.SCHEME=3^|00^|0^|0^|
    set "1st="
   (for /F "delims=" %%a in ('Type Some_Old.ini') do (
        If ".!1st!" EQU ".1" echo %%a
        If /i ".%%a" EQU ".SCHEME=3|10|0|0|" Set "1st=1"
    )
   )>>Some_New.ini
    Echo.output:
    Type Some_New.ini
    Exit /b
After adjusting to the name of your particular .ini file, that leaves you with two files. You'll have to handle the authorizations, backups, renames and deletes from there.
John A.

Re: Writing a batch file to amend .ini

Posted: 11 Feb 2016 16:53
by Raindancer
Sorry its taken me forever to reply! thank you. Ill go check it out.

Re: Writing a batch file to amend .ini

Posted: 11 Feb 2016 17:33
by foxidrive
Raindancer wrote:Sorry its taken me forever to reply! thank you. Ill go check it out.

It's nice that you came back to reply.

It's even nicer if you check it out first and come back and say "thank you" :)