Change a line in an external file

January 25, 2011 at 21:40:22
Specs: Win 7 Ultimate , 4.17Ghz 8GB ram
I want to create a script that calls a config file that will store information in it. And be able to have it change if the user wants to. I have the config file all set. but I dont know how to have it change the correct line in the config file

EX: 4:on
where 4 is the line number and on is the command
how do I make a batch script that will pick that line and change it to off?


See More: Change a line in an external file

Report •


#1
January 26, 2011 at 11:10:18
does the order of lines matter in that config file ?

i mean if you can put 4: in last line will it work ?

Subhash Chandra.
www.s-chandra.co.cc


Report •

#2
January 31, 2011 at 16:46:46
No because the file script that i have uses the number for what value it is calling

Report •

#3
February 1, 2011 at 10:08:35
untested...

type config.ini | Findstr /v "4:" >%temp%\1.txt
REM get the value of 4, suppose it is OFF now.
echo 4:off >>%temp%\1.txt
type %temp%\1.txt >config.ini


It will first take all values from your config file and store in a temp file.
then it will take the value of your config line and append in same temp file
now it wil take all content from temp file and save in config file.

Subhash Chandra.
www.s-chandra.co.cc


Report •

Related Solutions

#4
February 2, 2011 at 20:51:50
it worked :) thank you very much i have been looking for this for a while

Report •

Ask Question