Hello guys,
I would need to remove the last character ")" of a specific line. This can be from any line. Your help is appreciated. Below is the line.
HOSTNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP))
Please help.
Hello guys,
I would need to remove the last character ")" of a specific line. This can be from any line. Your help is appreciated. Below is the line.
HOSTNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP))
Please help.
Hello sang8g,
Welcome to forum, please use code tags for commands/codes/Inputs which you show us in your posts. For your request you can try following.
i-
a="HOSTNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP))"
echo ${a%)}
Output will be as follows.
HOSTNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
ii- If line is every time ending with character )
then
awk '{sub(/\)$/,X,$0);print}' Input_file
Output will be as follows.
HOSTNAME=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)
Hope this may help you.
Thanks,
R. Singh
Hello Ravinder Singh,
Thank you for your response. But yeah in a normal scenario. it works. But actually i am trying to do this in a script, so my script has the below lines
cp /root/new/test.prop /root/sid/
su -l suadm <<EOF
source /root/sid/test.prop
after sourcing it connecting it using sqlplus
by taking the conn strings from test.prop
file.
so in the test.prop
, ")" extra character should be removed and then source this test.prop
file and conn using sqlplus
.
Hello sang8g,
Not sure if I understand requirement completely but why should a tnsnames(actual file name for oracle) or test.prp file will NOT have complete pair of )
braces at first place. If still that is correct entry then could you please be more clear in your requirement because in my first post I have suggested one awk
solution which can help you if you only want to remove character )
and get the values.
Thanks,
R. Singh
actually my requirement is that i should open the test.prop file and remove the last character ")" from a particular line and then save and quit the file. this should be done by a script itself.
Hello sang8g,
Yes, following may help you in same.
awk '{sub(/\)$/,X,$0);print}' Input_file > temp_input_file
mv temp_input_file Input_file
There is one more option sed -i
but above option is more convenient. Hope this helps.
NOTE: You can change files names Input_file and temp_input_file accordingly.
Thanks,
R. Singh
Thanks Ravinder. That works !!!