How to get top level parent directory

Hi All,
I have a directory like this: /u01/app/oracle/11gSE1/11gR203

How do i get the top level directory /u01 from this? Tried dirname and basename but dint help. I can this using echo $ORACLE_HOME | awk -F"/" '{print "/"$2}'. But I am trying to find out if there is a better way of doing it other than using awk. Thanks in advance.

Try:

echo "${ORACLE_HOME%%/${ORACLE_HOME#*/*/}}"

Thanks a lot Scrutinizer. It worked. Does it work for any number of child directories? Would you mind explaining what exactly is happening here. Regex is new to me. So what are the symbols i need to escape to work in a ruby script. Thanks a lot. If the mod if busy, any one else could help me understand it. Thanks.

Try this in ruby:

topdir = `echo "${ORACLE_HOME%%/${ORACLE_HOME#*/*/}}"`

You're welcome. It should work for any number of subdirs. It is not regex, but Unix pattern matching within parameter expansion, in this case it is two parameter expansions in one...