Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2003
    Posts
    35

    Unanswered: Difficulties in this regex

    Hi`
    I have a difficulties to find the corect patern for the following string value:

    "20030815/ABC.SS20_0.dat"


    I d like to get word SS20_0,however i still could not get it work.
    Do you guys know what is the correct pattern of the regex for my purpose?

    i use

    echo $myvar | sed -e 's/myfailedpattern//g'



    Thanks

  2. #2
    Join Date
    Aug 2001
    Location
    UK
    Posts
    4,650

    Re: Difficulties in this regex

    Am I missing something ?

    $ export myvar="20030815/ABC.SS20_0.dat"
    $ echo $myvar
    20030815/ABC.SS20_0.dat
    $ echo $myvar | sed -e 's/SS20_0//g'
    20030815/ABC..dat
    $

    Cheers

    Sathyaram

    Originally posted by msetjadi
    Hi`
    I have a difficulties to find the corect patern for the following string value:

    "20030815/ABC.SS20_0.dat"


    I d like to get word SS20_0,however i still could not get it work.
    Do you guys know what is the correct pattern of the regex for my purpose?

    i use

    echo $myvar | sed -e 's/myfailedpattern//g'



    Thanks
    Visit the new-look IDUG Website , register to gain access to the excellent content.

  3. #3
    Join Date
    Jun 2002
    Location
    UK
    Posts
    525
    You want to strip out the first part and the last part and end up with SS20_0?

    You need a regex for the first part - I'm lazy, so I'll use: ^.*
    A regex for the part you want: SS20_0
    And a regex for the last part: \.dat

    Hold the part you want in a buffer using \( ... \) which in this instance will be the first buffer \1.

    Substitute that whole lot for the string in the buffer...


    echo 20030815/ABC.SS20_0.dat | sed 's/^.*\(SS20_0\)\.dat/\1/'

    Probably a little clearer if we use a different separator...

    echo 20030815/ABC.SS20_0.dat | sed 's#^.*\(SS20_0\)\.dat#\1#'
    Last edited by Damian Ibbotson; 08-15-03 at 10:15.

  4. #4
    Join Date
    Dec 2002
    Posts
    104
    Originally posted by Damian Ibbotson
    You want to strip out the first part and the last part and end up with SS20_0?

    You need a regex for the first part - I'm lazy, so I'll use: ^.*
    A regex for the part you want: SS20_0
    And a regex for the last part: \.dat

    Hold the part you want in a buffer using \( ... \) which in this instance will be the first buffer \1.

    Substitute that whole lot for the string in the buffer...


    echo 20030815/ABC.SS20_0.dat | sed 's/^.*\(SS20_0\)\.dat/\1/'

    Probably a little clearer if we use a different separator...

    echo 20030815/ABC.SS20_0.dat | sed 's#^.*\(SS20_0\)\.dat#\1#'

    Hello,

    just a try...

    echo 20030815/ABC.SS20_0.dat | cut -f2 -d.

    it will give u :
    SS20_0

    Hope this will help,
    Pooja

  5. #5
    Join Date
    Mar 2003
    Location
    shanghai,china
    Posts
    3
    maybe you can use awk to try it.

    export myvar="20030815/ABC.SS20_0.dat"

    echo $myvar |awk -F\. '{print $2}'

    you can get SS20_0

Posting Permissions

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