LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-15-2005, 07:02 AM   #1
basher400
Member
 
Registered: Mar 2005
Posts: 54

Rep: Reputation: 15
regex in paths


hi

i'm trying to get a certain part of the path into a var.

lets say I have the following path:
/usr1/web/java/A55771/

the "/usr1/web/java/" part will always be the same, what I am looking for is the "A55771" part. (this part might be "B66-154-89" in a different case)
so I did this:

Code:
PATH="/usr1/web/java/A55771/"
BASE="/usr1/web/java/"
MYDIR=`$PATH | sed s/"$BASE"//g`
MYDIR should hold "A55771/".

what am I doing wrong?
 
Old 06-15-2005, 07:48 AM   #2
perfect_circle
Senior Member
 
Registered: Oct 2004
Location: Athens, Greece
Distribution: Slackware, arch
Posts: 1,783

Rep: Reputation: 52
Code:
skalkoto@darkstar:~$ a="/usr1/web/java/A55771/"
skalkoto@darkstar:~$ b="/usr1/web/java/"
skalkoto@darkstar:~$ c="${a#$(echo $b)}"
skalkoto@darkstar:~$ echo $c
A55771/
skalkoto@darkstar:~$
 
Old 06-15-2005, 08:06 AM   #3
basher400
Member
 
Registered: Mar 2005
Posts: 54

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by perfect_circle
Code:
skalkoto@darkstar:~$ a="/usr1/web/java/A55771/"
skalkoto@darkstar:~$ b="/usr1/web/java/"
skalkoto@darkstar:~$ c="${a#$(echo $b)}"
skalkoto@darkstar:~$ echo $c
A55771/
skalkoto@darkstar:~$
thanks
 
Old 06-15-2005, 08:08 AM   #4
jonaskoelker
Senior Member
 
Registered: Jul 2004
Location: Denmark
Distribution: Ubuntu, Debian
Posts: 1,524

Rep: Reputation: 46
Quote:
what am I doing wrong?
MYDIR=`echo $PATH | sed s/"$BASE"//g`

And you may want to not use PATH if you don't know the function of the PATH variable in general (read the bash manual).

hth --Jonas
 
  


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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex Help cmfarley19 Programming 5 03-31-2005 11:13 PM
GNU C++ Regex lumux Programming 5 09-29-2003 11:51 PM
Automatically resolving WINDOWS paths to pre-configured Linux paths gazzy Linux - General 1 09-05-2003 11:15 PM
ip address REGEX Robert0380 Programming 16 08-15-2003 02:00 PM
regex stumper Silly22 Programming 4 07-07-2002 06:10 PM


All times are GMT -5. The time now is 01:40 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration