The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 and shell scripting languages 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 05:11 PM
Regular Expression question Katkota UNIX for Dummies Questions & Answers 6 05-14-2008 03:23 PM
question (regular expression related) metalwarrior UNIX for Dummies Questions & Answers 1 02-03-2008 11:51 PM
Regular Expression Question Krispy UNIX for Dummies Questions & Answers 3 01-20-2006 10:36 AM
question about regular expression brentdeback Shell Programming and Scripting 0 11-14-2005 04:04 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-27-2005
umen umen is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 239
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 (permalink)  
Old 12-27-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
in case of 'foo_ver1223i' what's your desired output?
I get '_ver1223i'.
  #3 (permalink)  
Old 12-27-2005
mahendramahendr mahendramahendr is offline Forum Advisor  
Registered User
  
 

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

just say

pwd | sed s/foo//g
  #4 (permalink)  
Old 12-27-2005
vgersh99's Avatar
vgersh99 vgersh99 is offline Forum Staff  
Moderator
  
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 5,119
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 (permalink)  
Old 12-27-2005
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
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.
  #6 (permalink)  
Old 12-28-2005
umen umen is offline
Registered User
  
 

Join Date: Aug 2005
Posts: 239
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 (permalink)  
Old 12-28-2005
Ygor's Avatar
Ygor Ygor is offline Forum Staff  
Moderator
  
 

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

  /blah1/blah2/blah3
  /blah1/blah2/blah3
Sponsored Links
Closed Thread

Bookmarks

Tags
regex, regular expressions

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:22 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0