Writing a batch file to amend .ini

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Raindancer
Posts: 2
Joined: 01 Feb 2016 08:40

Writing a batch file to amend .ini

#1 Post by Raindancer » 01 Feb 2016 08:43

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 :)

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Writing a batch file to amend .ini

#2 Post by thefeduke » 01 Feb 2016 11:18

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.

thefeduke
Posts: 211
Joined: 05 Apr 2015 13:06
Location: MA South Shore, USA

Re: Writing a batch file to amend .ini

#3 Post by thefeduke » 04 Feb 2016 03:02

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.

Raindancer
Posts: 2
Joined: 01 Feb 2016 08:40

Re: Writing a batch file to amend .ini

#4 Post by Raindancer » 11 Feb 2016 16:53

Sorry its taken me forever to reply! thank you. Ill go check it out.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Writing a batch file to amend .ini

#5 Post by foxidrive » 11 Feb 2016 17:33

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" :)

Post Reply