substring from string
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Shell > substring from string




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    substring from string  
Petterson Mikael


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-26-04 02:34 PM

Hi,

I have the following string,
'/app/eclipse/2.1.3/eclipse' and need the following
substring 'eclipse/2.1.3'

Any hints on how I can do this?

BR

//Mikael





[ Post a follow-up to this message ]



    Re: substring from string  
Charles Demas


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-26-04 03:34 PM

In article <408D102C.48FC985F@era.ericsson.se>,
Petterson Mikael  <mikael.petterson@nospam.se> wrote:
>Hi,
>
>I have the following string,
>'/app/eclipse/2.1.3/eclipse' and need the following
>substring 'eclipse/2.1.3'
>
>Any hints on how I can do this?

dirname $string | sed 's:/[a-z]*/:: ; s:.*:'&':'

untested


Chuck Demas

--
Eat Healthy        |   _ _   | Nothing would be done at all,
Stay Fit           |   @ @   | If a man waited to do it so well,
Die Anyway         |    v    | That no one could find fault with it.
demas@theworld.com |  \___/  | http://world.std.com/~cpd





[ Post a follow-up to this message ]



    Re: substring from string  
William Park


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-26-04 06:34 PM

Petterson Mikael <mikael.petterson@era.ericsson.se> wrote:
> Hi,
>
> I have the following string,
> '/app/eclipse/2.1.3/eclipse' and need the following
> substring 'eclipse/2.1.3'
>
> Any hints on how I can do this?
>
> BR
>
> //Mikael

man cut		--> -d -f
man awk		--> FS
man bash ksh	--> ${...#...}, ${...%...}

--
William Park, Open Geometry Consulting, <opengeometry@yahoo.ca>
Linux solution/training/migration, Thin-client





[ Post a follow-up to this message ]



    Re: substring from string  
joe@invalid.address


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-26-04 07:34 PM

Petterson Mikael <mikael.petterson@era.ericsson.se> writes:

> I have the following string,
> '/app/eclipse/2.1.3/eclipse' and need the following
> substring 'eclipse/2.1.3'
>
> Any hints on how I can do this?

If your shell supports the syntax:

$ x=/app/eclipse/2.1.3/eclipse
$ y=${x%/*}
$ echo ${y#/*/}
eclipse/2.1.3

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra





[ Post a follow-up to this message ]



    Re: substring from string  
rakesh sharma


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
04-26-04 10:35 PM

Petterson Mikael <mikael.petterson@era.ericsson.se> wrote in message news:<408D102C.48FC985F
@era.ericsson.se>...
> Hi,
>
> I have the following string,
> '/app/eclipse/2.1.3/eclipse' and need the following
> substring 'eclipse/2.1.3'
>
> Any hints on how I can do this?
>
> BR
>
> //Mikael

expr "X$string" : 'X/[a-z]*/\(.*\)/.*'

or,

sed -e 's:^/[^/]\{1,\}/\(.*\)/.*:\1:' <<[EOF]
$string
[EOF]





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:07 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register