Extract path within path

Hi,

I have a environmental variables,

 
ORACLE_HOME=/u01/oracle/ORCL/db/tech/10.2.0
ORACLE_SID=ORCL

Now I need to create a variable and need to extract some part from ORACLE_HOME. I need to get the path from ORACLE_HOME till ORACLE_SID as /u01/oracle/ORCL. I may need to check also the first occurance of ORCL in the whole path.

Can anybody suggest the best way to do it nawk or cut or substing.

Please advice.

Thanks and Regards,
Sreejit

ORACLE_HOME=/u01/oracle/ORCL/db/tech/10.2.0
ORACLE_SID=ORCL

echo ${ORACLE_HOME##*${ORACLE_SID}}
echo ${ORACLE_HOME%%${ORACLE_SID}*}

I hope this helps.

bakunin

misunderstood, removed.

You can do it with shell parameter expansion:

echo ${ORACLE_HOME%%/$ORACLE_SID*}

Thanks all..It was really quick...

I found this one good, echo ${ORACLE_HOME%%/$ORACLE_SID*}

Can you please explain what it does. Is it removing or cut the $ORACLE_SID from $ORACLE_HOME

Regards,
SReejit

Something like:

Check your shell man pages for more information. For example, if you use bash:

man bash |less -p'Parameter Expansion'

Thanks a lot.

Regards,
Sreejit