I am working in a ksh script.
I am reading a login, password, and database name from a pre-existing config file. Login and password are simple, I take the value after the first "=" sign, but the dbname has multiple equal signs in it. I have it working by temporarily reading the 23rd field, but the number of fields may vary in different environments depending on the number of servers. How can I identify the last delimiter and take the value after that?
Here is what I have now:
for LINE in `cat /config/db.properties|tr -d " )\r"`
do
VALUE=`echo $LINE | cut -f2 -d=`
KEY=`echo $LINE | cut -f1 -d=`
case $KEY in
ORACLE_USER_ID)
USERNAME=$VALUE;;
ORACLE_PASSWORD)
PASSWORD=$VALUE;;
ORACLE_URL)
DBNAME=`echo $LINE | cut -f23 -d=`;;
esac
done
echo " You are $USERNAME.\n Your password is $PASSWORD.\n You're logging on "
echo "to $DBNAME.\n"
My input is after removing carriage returns, spaces, and right parens is:
ORACLE_USER_ID=user12
ORACLE_PASSWORD=pswd12
ORACLE_URL=ORACLE_URL=jdbc:oracle:thin:@(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP(HOST=server1(PORT=1111(ADDRESS=(PROTOCOL=TCP(HOST=server2(PORT=2222(ADDRESS=(PROTOCOL=TCP(HOST=server3(PORT=3333(ADDRESS=(PROTOCOL=TCP(HOST=server4(PORT=4444(LOAD_BALANCE=yes(CONNECT_DATA=(SERVER=DEDICATED(SERVICE_NAME=oradb1
Output is:
You are user12.
Your password is pswd12.
You're logging on y\to oradb1.