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.

Required to get a portion of a text

Shell Programming and Scripting


Reply    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 06-15-2017
pokhraj_d pokhraj_d is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 27 June 2017, 9:11 AM EDT
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Required to get a portion of a text

Hello Gurus,
I have a filesystem like below :
HTML Code:
/u03/oracle/EBSDEV/fs1/EBSapps/appl
I want to get only the portion of the above text like below...
HTML Code:
/u03/oracle/EBSDEV
Can you please advice on this?

Thanks-
P
Sponsored Links
    #2  
Old Unix and Linux 06-15-2017
RudiC RudiC is online now Forum Staff  
Moderator
 
Join Date: Jul 2012
Last Activity: 20 August 2017, 7:34 AM EDT
Location: Aachen, Germany
Posts: 11,176
Thanks: 287
Thanked 3,444 Times in 3,173 Posts
How would you identify the partial string to extract?
- three levels deep?
- three levels chopped off from the end?
- contains "EBSDEV"?
- "fs1" and rest of line chopped off?
Where and how is that string stored, in a file, a (shell) variable, output of a command?
Sponsored Links
    #3  
Old Unix and Linux 06-15-2017
_Fabio_79 _Fabio_79 is offline
Registered User
 
Join Date: May 2017
Last Activity: 15 June 2017, 10:00 AM EDT
Location: Turin
Posts: 8
Thanks: 1
Thanked 1 Time in 1 Post
you could try this:

Code:
find / -maxdepth 3 -name EBSDEV

    #4  
Old Unix and Linux 06-15-2017
pokhraj_d pokhraj_d is offline
Registered User
 
Join Date: Jan 2012
Last Activity: 27 June 2017, 9:11 AM EDT
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Thank you for your advice. But the above code is giving such below details:

/u03/oracle/EBSDEV
/u08/oracle/EBSDEV
/u08nfs/oracle/EBSDEV


My requirement is only to get the "/u03/oracle/EBSDEV".

How to achieve this? Please advice.

Thanks-
P

---------- Post updated at 06:54 PM ---------- Previous update was at 06:48 PM ----------

Hello RudiC,

The below is the details:
Quote:
three levels deep?
Ans: Yes.. It should be 3 level deep.
Quote:
- three levels chopped off from the end?
Ans: No, the output should be /u03/oracle/EBSDEV
Quote:
- contains "EBSDEV"?
Ans: Yes.. It will contain EBSDEV
Quote:
- "fs1" and rest of line chopped off?
Ans: Yes, - "fs1" and rest of line will be chopped off
Quote:
Where and how is that string stored, in a file, a (shell) variable, output of a command?
Ans: The output of a command will be stored at a variable.

Thanks-
P
Sponsored Links
    #5  
Old Unix and Linux 06-15-2017
rdrtx1 rdrtx1 is offline
Registered User
 
Join Date: Sep 2012
Last Activity: 18 August 2017, 7:46 PM EDT
Location: Houston, Texas, USA
Posts: 950
Thanks: 0
Thanked 322 Times in 306 Posts

Code:
find /u03/oracle -maxdepth 1 -mindepth 1 -type d -name EBSDEV

Sponsored Links
    #6  
Old Unix and Linux 06-15-2017
Aia's Unix or Linux Image
Aia Aia is offline
Registered User
 
Join Date: May 2008
Last Activity: 2 August 2017, 1:08 AM EDT
Posts: 1,633
Thanks: 46
Thanked 623 Times in 584 Posts

Code:
$path="/u03/oracle/EBSDEV/fs1/EBSapps/appl"
echo ${path%/*/*/*}

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
Perl: batch replace a portion of text in files menteith Shell Programming and Scripting 3 11-04-2014 03:33 PM
parsing a portion of Data from a text file Lucky Ali Shell Programming and Scripting 8 09-28-2010 12:38 AM
Cutting out text from specific portion on filename GermanJulian Shell Programming and Scripting 16 05-12-2010 03:23 PM
How to extract a text portion from a file ejazs0 Shell Programming and Scripting 5 07-10-2009 02:18 AM
How to extract a portion of text from a log file atilano UNIX for Dummies Questions & Answers 2 01-27-2009 09:25 AM



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