Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting — Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Find directory immediately after the pattern dir name

Shell Programming and Scripting


Tags
unix

Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 1 Week Ago
Yuvaan12 Yuvaan12 is offline
Registered User
 
Join Date: May 2017
Last Activity: 29 May 2017, 4:47 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Find directory immediately after the pattern dir name

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


Code:
/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

Last edited by RudiC; 1 Week Ago at 08:23 AM.. Reason: Removed ICODE tags.
Sponsored Links
    #2  
Old Unix and Linux 1 Week Ago
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 29 May 2017, 6:37 AM EDT
Location: Aachen, Germany
Posts: 10,830
Thanks: 272
Thanked 3,324 Times in 3,061 Posts
Do you want to modify the output of an ls command, edit a file, change a shell variable?
Sponsored Links
    #3  
Old Unix and Linux 1 Week Ago
Yuvaan12 Yuvaan12 is offline
Registered User
 
Join Date: May 2017
Last Activity: 29 May 2017, 4:47 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Basically I am storing the current directory path
as
Code:
_C_CDIR=$PWD

which gives me the complete path

Code:
 
 /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"
    #4  
Old Unix and Linux 1 Week Ago
RudiC RudiC is offline Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 29 May 2017, 6:37 AM EDT
Location: Aachen, Germany
Posts: 10,830
Thanks: 272
Thanked 3,324 Times in 3,061 Posts
Hmmm - this is not much clearer. Would this help:

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

Sponsored Links
    #5  
Old Unix and Linux 1 Week Ago
Yuvaan12 Yuvaan12 is offline
Registered User
 
Join Date: May 2017
Last Activity: 29 May 2017, 4:47 AM EDT
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you so much RudiC
Looks like this is working... let me test it completely.
Thanks once again.Linux
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
How to find files in a pattern directory? shhrikanth Shell Programming and Scripting 2 12-29-2011 09:05 AM
find the file names having specified pattern at specified position in the current directory vk39221 UNIX for Dummies Questions & Answers 3 08-30-2011 07:59 PM
Deleting a type of file in a directory immediately it occurs jitendra.pat04 Shell Programming and Scripting 4 08-13-2011 02:10 AM
To find a character immediately following a specified String The Observer Shell Programming and Scripting 3 07-23-2008 10:33 AM
To find a character immediately following a word The Observer Shell Programming and Scripting 2 07-11-2008 07:21 AM



All times are GMT -4. The time now is 07:33 AM.