![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Question on Regular Expression | Katkota | UNIX for Dummies Questions & Answers | 14 | 05-18-2008 02:11 PM |
| Regular Expression question | Katkota | UNIX for Dummies Questions & Answers | 6 | 05-14-2008 12:23 PM |
| question (regular expression related) | metalwarrior | UNIX for Dummies Questions & Answers | 1 | 02-03-2008 08:51 PM |
| Regular Expression Question | Krispy | UNIX for Dummies Questions & Answers | 3 | 01-20-2006 07:36 AM |
| question about regular expression | brentdeback | Shell Programming and Scripting | 0 | 11-14-2005 01:04 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
in case of 'foo_ver1223i' what's your desired output?
I get '_ver1223i'. |
|
#3
|
|||
|
|||
|
don't include .* in front of foo...
just say pwd | sed s/foo//g |
|
#4
|
||||
|
||||
|
Quote:
|
|
#5
|
||||
|
||||
|
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.
__________________
War doesnt determine who is right, it determines who is left |
|
#6
|
|||
|
|||
|
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
|
||||
|
||||
|
Try...
Code:
$ echo " > /blah1/blah2/foo_v123/blah3 > /blah1/blah2/foo/blah3 > " | sed 's:foo[^/]*/::' /blah1/blah2/blah3 /blah1/blah2/blah3 |
||||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|