If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Unix Shell Scripts > Difficulties in this regex

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 08-14-03, 13:28
msetjadi msetjadi is offline
Registered User
 
Join Date: Jun 2003
Posts: 35
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
Reply With Quote
  #2 (permalink)  
Old 08-14-03, 13:35
sathyaram_s sathyaram_s is offline
Super Moderator
 
Join Date: Aug 2001
Location: UK
Posts: 4,543
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

Quote:
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.
Reply With Quote
  #3 (permalink)  
Old 08-15-03, 05:58
Damian Ibbotson Damian Ibbotson is offline
Padawan
 
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 09:15.
Reply With Quote
  #4 (permalink)  
Old 08-15-03, 10:29
pooja pooja is offline
Registered User
 
Join Date: Dec 2002
Posts: 104
Quote:
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
Reply With Quote
  #5 (permalink)  
Old 08-19-03, 02:39
henbance henbance is offline
Registered User
 
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On