Find directory immediately after the pattern dir name

Hi,
From below directories path I need the directory which comes immediately after the "DataPath"

/var/errors/LogDefaultPath/DataPath/Data01/Data02    (Directory name "Data01" is the result from this path)
/var/errors/LogDefaultPath/DataPath/Log01/Log0202    (Directory name "Log01" is the result from this path)
/var/errors/LogDefaultPath/DataPath/Planning         (Directory name "Planning" is the result from this path)
/var/errors/LogDefaultPath/DataPath/Support          (Directory name "Support" is the result from this path)
/var/errors/LogDefaultPath/DataPath/Support/Contents  (Directory name "Support" is the result from this path)

Please help on this.
Thanks

Do you want to modify the output of an ls command, edit a file, change a shell variable?

Basically I am storing the current directory path
as

_C_CDIR=$PWD

which gives me the complete path

 
 /var/errors/LogDefaultPath/DataPath/Data01/Data02
 

Now If my path contains "DataPath" I need to store the immediate directory name "Data01" into some variable and append this to another variable and use that variable at later stage in script.

Likewise I need to do for all the directory paths ... find ONLY immediate directory name after "DataPath"

Hmmm - this is not much clearer. Would this help:

TMP=${PWD#*DataPath/}
_C_CDIR=${TMP%%/*}

Thank you so much RudiC
Looks like this is working... let me test it completely.
Thanks once again.:slight_smile: