extracting a string

Hi All,

I am writing a shell script for which I am stuck with an extraction part.

I arrived till extraction of a path of file. Lets take an example.

I now have a file which contains following one line:

2348/home/userid/mydir/any_num_dir/myfile.text

Now I want to extract only "/home/userid/mydir/any_num_dir/" part of the string. Note that initial number can be anything, any number if digits.

To simplify the problem statement, I want to extract from a line, only part which is between first "/" and last "/", test should be ignored.

I need this because I want to change directory to /home/userid/mydir/any_num_dir/

Please help.

Thanks!

man dirname

awk 'BEGIN { FS=OFS="/" } { $1=$NF=""; print}