Get portion of string from the end

Hi all,

Can anyone suggest a way to get a portion of string from the end?

So:

$ORACLE_SID=blt10cr1

We can drop the final '1' and end up with:

$ORACLE_SID=blt10cr

So far I have the following:

echo $ORACLE_SID | cut -c1-5

and

echo $ORACLE_SID |  cut -c1-6 | rev

any ideas?

Thanks in advance.

jd

$ echo $ORACLE_SID | sed 's/.$//'
blt10cr

If its bash:

echo "${ORACLE_SID:0:${#ORACLE_SID}-1}"

hth

Try also

echo "${ORACLE_SID%?}"
blt10cr

thank guys that works.

echo "${ORACLE_SID%?}"
blt10cr

nice and simple :slight_smile: