running a for-loop works as long as I filter out the commented lines, which i not what I need.
Going for a "while read line" statement does print the comments and writes them to the tempfile but I'm not able to enter/modify the values param by param, as the additional read statement is beeing "ignored".
The easiest way would be some kind of array, but I didn't got it working so far. Is there another way to get this working?
bash-3.00$ ./prop_test.sh
Do you install in test or prod? prod
Set Max.defBpId - Actual (CH999148):
Set Max.env - Actual (T):
Set Max.exceptionFile - Actual (exception.txt):
Set Max.fileRoot - Actual (/opt/SISwebMAX/webmaxTest/Service):
....
The properties file is used by a java based application.
So if I understood it correct, you have problems with the substitution in the file.
If you have no problem to set up the while/read loop to get the wanted input, you can use the values stored in variables with for example sed to exchange the current values in the config file with the new ones.
Here a general example how substitute patterns:
# you got VAR filled with a value by your former read/while loop of course
sed "s/oldvalue/${VAR}/g"
Do this for several of your patterns and write it to a tmp file and maybe mv it over the original. Could take a backup before doing it.
thanks for your answer and your help trying to get the goal.
My problem is not, to exchange value "a" with value "b", but the interactive part above. The example there is how the prompts should look like. but doing this with a "while read" loop fails.
This is what I've created:
while read line
do
comment=`echo $line | sed -e 's/#.*/#/'`
if [ $comment = "#" ]; then
echo "$line" | sed -n 's/#.*/&/p' >>$tmpfile
else
cf_key=`echo $line | awk 'BEGIN {FS = "="} {print $1}'`
cf_val=`echo $line | awk 'BEGIN {FS = "="} {print $2}'`
printf "Set $cf_key - Actual ($cf_val): \n"
read value
if [ $value = "" ]; then
echo "$cf_key=$cf_val" >>$tmpfile
else
echo "$cf_key=$value" >>$tmpfile
fi
fi
done < $config
Running this will result in several lines of output on screen, but no input reading prompt (read value, get ignored).
My question is: Is there another way to get this working?
The for-loop is not an option as I've written at the begin, because it does'nt handle the file line by line (whitespace problem). Except if ther's a way to advise the for-loop to ignore the whitespace. I've alread played around with setting of IFS, but I didn't come any further.
there was already an input stream being put to by "< $config"
is it possible for you to not loop in the config file but add the parameters in the script itself?