Hi all,
I am trying to replace a string in a line using the "sub" function of "nawk" command.
I want to remove the "{${DB2_HOME}/lib:" from the line in a file called Env.sh and copy to a file called Env_new.sh
Here is my code:
echo " INFO: Modifying the Env.sh file"
nawk '
{FS="="}
$0 ~ /^SHLIB_PATH=/ && $0 ~ /DB2_HOME/ {
print "#"$0"";
sub("{${DB2_HOME}/lib:", ""); print ;
next }
{print;next}
' Env.sh > Env_new.sh
The data in the file is
SHLIB_PATH=${JRE_BIN}:${JRE_LIB}:${CROSSWORLDS}/lib:${CROSSWORLDS}/bin:${MQ_LIB}:${DB2_HOME}/lib:${WREQUIRED}:$SHLIB_PATH
The code works fine if I do not include "$" in the function sub("{${DB2_HOME}/lib:", "");. But I need to remove that "$" too from the String. I did try using the \ (escape) but that did not work either. My Field Separator (FS) is already set to "=" which I am using at some other part of the code.
Any suggestions on how I can overcome with this problem.
Thanks,
Ravi Pydi
I am trying to replace a string in a line using the "sub" function of "nawk" command.
I want to remove the "{${DB2_HOME}/lib:" from the line in a file called Env.sh and copy to a file called Env_new.sh
Here is my code:
echo " INFO: Modifying the Env.sh file"
nawk '
{FS="="}
$0 ~ /^SHLIB_PATH=/ && $0 ~ /DB2_HOME/ {
print "#"$0"";
sub("{${DB2_HOME}/lib:", ""); print ;
next }
{print;next}
' Env.sh > Env_new.sh
The data in the file is
SHLIB_PATH=${JRE_BIN}:${JRE_LIB}:${CROSSWORLDS}/lib:${CROSSWORLDS}/bin:${MQ_LIB}:${DB2_HOME}/lib:${WREQUIRED}:$SHLIB_PATH
The code works fine if I do not include "$" in the function sub("{${DB2_HOME}/lib:", "");. But I need to remove that "$" too from the String. I did try using the \ (escape) but that did not work either. My Field Separator (FS) is already set to "=" which I am using at some other part of the code.
Any suggestions on how I can overcome with this problem.
Thanks,
Ravi Pydi