The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
Google UNIX.COM


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here.

More UNIX and Linux Forum Topics You Might Find Helpful
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

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 12-27-2005
Registered User
 

Join Date: Aug 2005
Posts: 229
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
Reply With Quote
Forum Sponsor
  #2  
Old 12-27-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
in case of 'foo_ver1223i' what's your desired output?
I get '_ver1223i'.
Reply With Quote
  #3  
Old 12-27-2005
Registered User
 

Join Date: Dec 2005
Location: London
Posts: 222
don't include .* in front of foo...

just say

pwd | sed s/foo//g
Reply With Quote
  #4  
Old 12-27-2005
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 3,029
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'?
Reply With Quote
  #5  
Old 12-27-2005
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 295
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
Reply With Quote
  #6  
Old 12-28-2005
Registered User
 

Join Date: Aug 2005
Posts: 229
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
Reply With Quote
  #7  
Old 12-28-2005
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,249
Try...
Code:
$ echo "
>   /blah1/blah2/foo_v123/blah3
>   /blah1/blah2/foo/blah3
> " | sed 's:foo[^/]*/::'

  /blah1/blah2/blah3
  /blah1/blah2/blah3
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 05:30 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0