Regular expression question


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Regular expression question
# 1  
Old 12-27-2005
Regular expression question

hi
i need to wipe out something from giving path i have some thing like that :
pwd | sed 's/.*foo//'
it is working fine when I have path like : /blah/balh1/foo/moo
so it erasing me all that comes before the foo including the foo
but I have problem when I have dir by the name of "foo_ver1223i"
how can I build regular expression that take into consideration if its "foo" or "foo_blah123i"

tnx
# 2  
Old 12-27-2005
in case of 'foo_ver1223i' what's your desired output?
I get '_ver1223i'.
# 3  
Old 12-27-2005
don't include .* in front of foo...

just say

pwd | sed s/foo//g
# 4  
Old 12-27-2005
Quote:
Originally Posted by mahendramahendr
don't include .* in front of foo...

just say

pwd | sed s/foo//g
...and what will that do in case of '/blah/balh1/foo/moo'?
# 5  
Old 12-27-2005
Hi,
If you still want to replace pattern that is foo....., then what you need to do is

s/.*foo.*//g

remember .* means any character repeated any number of times.
I suggest go thru the sed man page to get more idea of these regular expressions.
# 6  
Old 12-28-2005
well this have some problem

you see ..
when i do : s/.*foo*.//g im im wiping out all the line ( i guess )
in both sides of the *foo* but i like to wipe out only the what is until the "foo*" including it . for example:
say i have :
/blah1/blah2/foo_v123/blah3
after the rexp i expect to get :
/blah1/blah2/blah3

and if i get only
/blah1/blah2/foo/blah3
after the rexp i expect to get also :
/blah1/blah2/blah3


i hope i now its clear now
thanks allot
# 7  
Old 12-28-2005
Try...
Code:
$ echo "
>   /blah1/blah2/foo_v123/blah3
>   /blah1/blah2/foo/blah3
> " | sed 's:foo[^/]*/::'

  /blah1/blah2/blah3
  /blah1/blah2/blah3

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Regular expression question

Hi guys, I need a help with a query. Basically i want to know the difference between (0+01)* and ((0+01)*)* . It seems whatever string can be generated by the first RE can also be generated by second and they should essentially be same. Am i missing something? (1 Reply)
Discussion started by: srkmish
1 Replies

2. UNIX for Dummies Questions & Answers

Regular Expression Question

Hello, I'm trying to rename a bunch of files that were named incorrectly. I know a little about regular expressions but I'm not very good at them. Here is the image of the file names: http://i47.tinypic.com/np2gxi.jpg I'm trying to change the 20111116 at the beginning to 20101116 for all... (2 Replies)
Discussion started by: nastyn8
2 Replies

3. Programming

Perl: How to read from a file, do regular expression and then replace the found regular expression

Hi all, How am I read a file, find the match regular expression and overwrite to the same files. open DESTINATION_FILE, "<tmptravl.dat" or die "tmptravl.dat"; open NEW_DESTINATION_FILE, ">new_tmptravl.dat" or die "new_tmptravl.dat"; while (<DESTINATION_FILE>) { # print... (1 Reply)
Discussion started by: jessy83
1 Replies

4. UNIX for Dummies Questions & Answers

a question about a regular expression

I like to loop a list of files which named file1, file2, file3, file4, etc if I like to loop them all over for f in file1, file2, file3, file4 do echo "processing" $f done how to use a regular expression to loop file$i instead? Thank you. (4 Replies)
Discussion started by: ksgreen
4 Replies

5. Shell Programming and Scripting

Easy Perl regular expression question

Hey all! what matching expression might I use to match all characters included in \W, EXCEPT < and > ? for example: @tokens=split(/ ???? /,$string); I've dubiously tried \W but this clips off the first letter of each "token", for some reason ... (2 Replies)
Discussion started by: applefat
2 Replies

6. UNIX for Dummies Questions & Answers

Question on Regular Expression

Folks; Could some one tell me what these 2 regular expressions mean: */(*)/* (\d\d\d\d/\d\d/\d\d/*?) (14 Replies)
Discussion started by: Katkota
14 Replies

7. UNIX for Dummies Questions & Answers

Regular Expression question

Folks; I have 3 questions & any help with them would be really appreciated: If i have a list of directories, for example: /fs/pas/2007/4/6/2634210/admdat/examin /fs/pas/2007/4/6/2634210/admdat2/stat /fs/pas/2007/4/6/2634210/admdat3/data /fs/pas/2007/4/6/2634210/im_2/0b.dcm Now; my... (6 Replies)
Discussion started by: Katkota
6 Replies

8. UNIX for Dummies Questions & Answers

question (regular expression related)

anyone knows what does this regular expression match for? \(3,\).*\1.*\1 (1 Reply)
Discussion started by: metalwarrior
1 Replies

9. UNIX for Dummies Questions & Answers

Regular Expression Question

Hi - I am trying to ignore the following items from a list. lp0 lp11 lp12 lp14 The following code works fine, but I was wondering if there was a tidier way to write the lp regular expression? egrep -v "lp" Thanks in advance. (3 Replies)
Discussion started by: Krispy
3 Replies

10. Shell Programming and Scripting

question about regular expression

why does * highlight everything in it... shouldn't it only highlight capital letters? (0 Replies)
Discussion started by: brentdeback
0 Replies
Login or Register to Ask a Question