sed: removing any and all trailing digits?

We have a large number of oracle database related scripts that utilize the environment variables $ORACLE_SID and $DBNAME. In a single instance database the $ORACLE_SID is the same as the database name $DBNAME. So we have simply set DBNAME = $ORACLE_SID. However, now that we are clustering with RAC, we have multiple $ORACLE_SID variables for each $DBNAME. Which means that DBNAME != $ORACLE_SID. An oracle provided script (oraenv) sets up most the environment automatically but does not set up $DBNAME.

Luckily, the $ORACLE_SID variables are just the $DBNAME with the node number added to the end. E.g. $DBNAME=ORCL $ORACLE_SID=ORCL1

What I need is a way to remove any and all digits from the end of the $ORACLE_SID variable. It should leave any digits that are at the beginning or middle of the $ORACLE_SID.

End result:

$ORACLE_SID     $DBNAME
ORCL                ORCL
ORCL1              ORCL
ORCL23             ORCL
4ORCL              4ORCL
4ORCL3            4ORCL
OR4CL              OR4CL

Thanks in advance!

If you have this in your file:

ORCL                ORCL
ORCL1              ORCL
ORCL23             ORCL
4ORCL              4ORCL
4ORCL3            4ORCL
OR4CL              OR4CL
sed 's/[0-9]\+ //' file

should return this:

ORCL                ORCL
ORCL             ORCL
ORCL            ORCL
884ORCL              4ORCL
4ORCL           4ORCL
OR4CL              OR4CL

Try this :

$ DBNAME=`echo $ORACLE_SID | sed -e "s/[0-9]*$//"`

sed -e "s/[0-9]*$//" works perfectly.

what does the "*$" actually mean?

Thanks!

You should read it more like this

[0-9]* means any occurence of numbers
$ means from the end

So [0-9]*$ means any occurence of numbers from the end (in other words any trailing numbers)

Ahhh, so it works back from the end until it hits a non-number character.

Brilliant, thanks!