getting part of directory after a certain /


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting getting part of directory after a certain /
# 1  
Old 04-22-2012
getting part of directory after a certain /

i have a directory like this:

i want to get the subpaths:
/home/user/public_html/a/b
subpath= a/b

/home/user/public_html/a/b/c
subpath= a/b/c


i can get the user like
Code:
echo $fulldirectory |awk -F/ '{print $3}'

but im not sure how to get the rest of it after public_html

any ideas?
thanks!
Moderator's Comments:
Mod Comment Link: How to use code tags

Last edited by Scrutinizer; 04-22-2012 at 03:00 AM..
# 2  
Old 04-22-2012
Code:
echo $fulldirectory | cut -d / -f 4-

This User Gave Thanks to Skaperen For This Post:
# 3  
Old 04-22-2012
Code:
echo "${fulldirectory#/*/*/*/}"

This User Gave Thanks to Scrutinizer For This Post:
# 4  
Old 04-22-2012
thanks for answering Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Linux cant cd into directory and part of group

I am part of the group group1. The directory permission I am trying to cd into are 770 for both the parent directory and child directory but I still can not cd into. What am I doing wrong? $ ls -l /NAS/infa/ drwxrwxr-x. 22 user1 group1 506 Jun 6 17:05 infa_shared $... (5 Replies)
Discussion started by: cokedude
5 Replies

2. UNIX for Advanced & Expert Users

A way to print only part of directory path

Hi, So I struggled to find a solution to the following problem: I want to make sed print only part of multiple different paths. So lets say we have /path/path1/path2/logs/bla/blabla /path/path1/path2/path3/logs/yadda/yadda/yadda Can someone suggest a way to make sed or other... (5 Replies)
Discussion started by: dampio
5 Replies

3. Shell Programming and Scripting

Add part of directory name to filename

Hello, I need to add a part of folder name to the files inside it. For instance the file is HMCBackup_20150430.155027.tgz and it is under directory /nim/dr/HMCBackup/cops22 I need to add cops22 to the file name so as it would be cops22_HMCBackup_20150430.155027.tgz Any help in doing... (10 Replies)
Discussion started by: hasn318
10 Replies

4. Shell Programming and Scripting

Selecting/using part of directory names in script

I'm making a shell script to: -copy directories to a new location -perform conversions on the files within the copied directories -move the newly created files to a new directory Please see my super basic script and notes below... and thank you thank you thank you in advance !! ... (1 Reply)
Discussion started by: kayzee
1 Replies

5. UNIX for Dummies Questions & Answers

Renaming files with part of their pathname and copying them to new directory

Hi I think this should be relatively simple but I can't figure it out. I have several files with the same name in different folders within a directory (the output of a program that I ran). Something like this: ./myAnalysis/item1/round1/myoutput.txt ./myAnalysis/item1/round2/myoutput.txt... (2 Replies)
Discussion started by: jullee
2 Replies

6. UNIX for Dummies Questions & Answers

Remove part of file names in a directory

Hi, i have a directory full of pictures, .jpg files. Half of them begin with "beach_" (for ex beach_123_123456.jpg) i'm looking for a command to remove the "beach_" from all files in the directory. thanks (4 Replies)
Discussion started by: robertmanalio
4 Replies

7. Shell Programming and Scripting

listing Directory chronologically based on part of file name

hi Everbody, I had file names as shown file_01_20101104.txt file_01_20101105.txt file_02_20101104.txt file_01_20101205.txt file_03_20101104.txt file_02_20101105.txt Now i want to list them based on the date in the file name as shown... file_01_20101104.txt file_02_20101104.txt... (3 Replies)
Discussion started by: Reddy482
3 Replies

8. Shell Programming and Scripting

Bash: How to get part of the directory name?

How can I write a script that determines the directory the user is in, and displays that path up until a particular point? Specifically, I need to find the text "packages" in the directory name, then I need to capture that directory and the one below it. For example, if the user is in the... (5 Replies)
Discussion started by: RickS
5 Replies

9. Shell Programming and Scripting

current directory as part of the csh prompt

I would like my csh prompt to behave like the linux csh prompt setting done by linux command (set prompt="%n@%m %c]$ ") how do I do that? What I'm trying to do is that I would like to see what directory I'm in by looking at the prompt. I've figured out that %n is like $user, and %m is like... (3 Replies)
Discussion started by: jamesloh
3 Replies
Login or Register to Ask a Question