Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2004
    Posts
    1

    Red face Unanswered: Bourne shell + String operations

    Hi,

    Does anyone know how to extract an element from a string in the Bourne Shell? For example, if I have this string

    "elem1--elem2--elem3"

    how can I get "elem1"?
    how can I delete it?

    Thanx a lot

  2. #2
    Join Date
    Jan 2004
    Location
    Bordeaux, France
    Posts
    320
    A solution :

    Code:
    str="elem1--elem2--elem3"
    elm=`echo "$string" | sed 's/--.*//'
    str=`echo "$string" | sed 's/^[^-]*--//'
    Jean-Pierre.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •