modifying parameter file using command line

Hi,

Is there a way to modify a parameter file's parameter using command line? e.g. to add text to a parameter like below:

parameter=val1;val2;val3;

now to add new value as below

parameter=valnew;val1;val2;val3;
baberaminAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NVITCommented:
set parameter=val1;val2;val3
echo %parameter%
set parameter=valnew;%parameter%
echo %parameter%

Open in new window

0
baberaminAuthor Commented:
keep in mind file has many other parameters and I want to change  only one
0
NVITCommented:

keep in mind file has many other parameters and I want to change  only one
If you give examples, it would be easier to provide help.
0
Cloud Class® Course: SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

baberaminAuthor Commented:
e.g.

parameter1=val1;val2;val3;
parameter2=abc
parameter3=xyz
0
NVITCommented:
I presume that's the existing, before values.
What's the new, after values?
Where are the new value coming from... another file?
0
baberaminAuthor Commented:
Existing
=======
parameter1=val1;val2;val3;
parameter2=abc
parameter3=xyz


After
====
parameter1=val1;val2;val3;val4;
parameter2=abc
parameter3=xyz


Not from file. From anywhere.
0
NVITCommented:
Make a file named AddParam.bat and add this code.
@echo off
setlocal enabledelayedexpansion

REM Adds a parameter value to an existing parameter field in a text file PFile. e.g.
REM 	AddParam params.txt param2 newval2
REM PFile structure assumption:
REM 	param1=1a
REM 	param2=2a;2b
REM 	param3=3a;3b;3c
REM 	param4=4a;4b;4c
REM 	...
REM Makes new parameter file newfile.txt in current folder. Adjust the path & filename to your needs.

set PFile=%1
set PField=%2
set PNewVal=%3
set PNewFile=newfile.txt

if exist %PNewFile% del /q %PNewFile%

if [%PFile%] equ [] echo Missing Parameter filename& exit /b 1
if [%PField%] equ [] echo Missing Parameter field name to revise& exit /b 1
if [%PNewVal%] equ [] echo Missing Parameter value to add& exit /b 1
if not exist %PFile% echo File %PFile% does not exist& exit /b 1
find /i "%PField%=" %PFile%>nul
if %errorlevel% gtr 0 echo Parameter field: %PField% not found& exit /b 1

for /f "tokens=1-2 delims==" %%a in ('type %PFile%') do (
	if /i [%PField%] equ [%%a] (
		echo [%PField%] equ [%%a]
		echo %PField%=%%b;%PNewVal%
		echo %PField%=%%b;%PNewVal%>> %PNewFile%
		set found=1
	) else (
		echo %%a=%%b>> %PNewFile%
	)
)
if [%found%] equ [] del /q %PNewFile%& exit /b 1
exit /b 0

Open in new window


Example params.txt:
param1=1a
param2=2a;2b
param3=3a;3b;3c
param4=4a;4b;4c

Open in new window


Example run:
AddParam params.txt param2 newval2

Open in new window


newfile.txt
param1=1a
param2=2a;2b;newval2
param3=3a;3b;3c
param4=4a;4b;4c

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
baberaminAuthor Commented:
Thanks.
Is it DOS command prompt code or Windows Powershell?
0
NVITCommented:
DOS
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Server OS

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.