LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 11-23-2010, 09:02 PM   #1
john206
LQ Newbie
 
Registered: May 2010
Posts: 11

Rep: Reputation: 0
Unhappy How to extract path name starting with specific folder


Hello guys,

Im writing a script that extracts part of the path name:



I drop a file in terminal and set the directory name of the file to x using dirname $0
note: ( directory is different every time since not all files are from the same location)



ex.
x="/home/Downloads/yesterday/photo/.../image.png" /image.png

/.../ means I dont know the name of folders between but I know the path name always starts with photo

and I want to capture directory after "photo" and store it like this:

y=/photo/image.png"
then something like
code:
cp file $y



All helps appreciated

Last edited by john206; 11-23-2010 at 09:14 PM.
 
Old 11-23-2010, 09:56 PM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Assuming for example you want to extract x/y/z/image.png from /home/Downloads/yesterday/photo/x/y/z/image.png (which is not what you illustrated but may have been what you meant):
Code:
x=/home/Downloads/yesterday/photo/x/y/z/image.png
echo ${x##*/photo/}
 
Old 11-23-2010, 10:13 PM   #3
john206
LQ Newbie
 
Registered: May 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by catkin View Post
Assuming for example you want to extract x/y/z/image.png from /home/Downloads/yesterday/photo/x/y/z/image.png (which is not what you illustrated but may have been what you meant):
Code:
x=/home/Downloads/yesterday/photo/x/y/z/image.png
echo ${x##*/photo/}

Thank you very much, it worked like a charm
 
Old 11-23-2010, 10:39 PM   #4
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Quote:
Originally Posted by john206 View Post
Thank you very much, it worked like a charm
That's good. It is bash parameter expansion. Threads can be marked SOLVED via the Thread Tools menu.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Way to make autofs mount to specific USB flash drive to specific folder? utahnix Linux - Software 2 11-24-2010 05:27 PM
tar extract specific directory lrt Linux - Software 7 12-01-2007 08:40 AM
How to extract specific directory from a TAR file? Micro420 Linux - General 4 04-18-2007 12:04 AM
How To extract .tar.gz To A Specific Directory? George2 Linux - Software 4 02-18-2006 07:01 AM
Extract specific files from .tgz dgermann Linux - Newbie 6 08-25-2004 10:39 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 12:02 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration