How to find last delimiter in line?

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.

With awk you can get the last field as follow:

DBNAME=`echo $LINE | awk -F= '{print NF}'`

Regards

Thanks Franklin. I added a $ in front of the NF and it worked perfect!

DBNAME=`echo $LINE | awk -F= '{print $NF}'`

O my, I forgot the $ sign, but glad to know you solve your problem.

Regards

You can do the same with sed too:

print - $string | sed 's/.*=//'

This works because regular expressions are by default "greedy": the regexp engine tries to match as much as possible. In this case it matches every occurence of "=" up to the last one, so that ".*=" (any number of any character followed by an equal sign) is still fulfilled.

bakunin