You are not logged in.
I have a file called prog.conf with a range of variables in it and I am trying to replace a variable in the conf file.
The conf file is called using the SOURCE command
I want it to incrementaly update the variable.
So if it is 1 one it becomes 2, etc.
I've tried the following but SED doesn't like it and it errors out. Here is the code.
In the prog.conf file there is a line that says
input_variable=1
I've tried
prev_seg="input_variable=$input_variable"
read wait
input_variable=$(($input_variable + 1))
next_seg="input_variable=$input_variable"
sed -i "$prev_seg/$next_seg/g" prog.conf
There is a probably much better way of doing all of this, but SED is my main issue. Any ideas?
Offline
awk -F '=' '/^input_variable/ { print "input_variable=" $2+1; } !/^input_variable/ {print $0;}' infile > outfile
mv outfile infile
EDIT: actually sed will do this just fine too if you use double quotes around the sed string - but yours fails as that is just not a sed command. That should be:
sed -i "s/$prev_seg/$next_seg/" prog.conf
You need to use the 's' command, and the 'g' is irrelevant in this case.
Last edited by Trilby (2014-02-10 13:02:16)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline