Hi All,
point 1. I have n number of environment variable files in different folders. All file names are ending with one thing common ie, *envset.sh
point 2. All these contains Varilables and some other information like following
*envset.sh ===>>
CORE_DB2_ROOT_JAVA=${CORE_DB2_ROOT_JAVA}
# Add quotes around the name in case there are spaces in the name.
CORE_DB2_ROOT_JAVA="$CORE_DB2_ROOT_JAVA"
echo CORE_DB2_ROOT_JAVA [$CORE_DB2_ROOT_JAVA]
CORE_WAS_HOME=${CORE_WAS_HOME}
# Add quotes around the name in case there are spaces in the name.
CORE_WAS_HOME="$CORE_WAS_HOME"
echo CORE_WAS_HOME="$CORE_WAS_HOME"
DB_USER_NAME=${DB_USER_NAME}
DB_USER_NAME="$DB_USER_NAME"
point 3 I have one file named tokenvalues.txt which contains the variable name and values to that variables.
tokenvalues.txt
CORE_DB2_ROOT_JAVA=/java/bin
CORE_WAS_HOME=/home/was/path
DB_USER_NAME=db2admin.
Point 4: Now using this tokenvalues.txt as a input file i am going to replace all the variables in *envset.sh that are matching the string ${varname}
following is the code file (tokenreplace.sh) that is written
tokenreplace.sh >>
for file in `find . -name "*env.sh" -print`
do
awk -F= 'NR==FNR {_[$1]=$2; next} _[$1] {print $1,_[$1];next}1' OFS="=" tokenvalues.txt $file > tmp; mv tmp $file;
echo $file
done
point 5 : but this is replacing all the instances wherever it is matching variable name from input file. where as i jst want to replace those where
varname={varname} is matching.
Any help on this will be strongly appreciated.
Thanks in advance
Nitin