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
shell variables and sed substitution duderonomy UNIX for Advanced & Expert Users 2 05-04-2008 11:54 PM
how to pass variables surrounded in double quotes to awk? cruiser AIX 4 03-24-2006 02:12 PM
double variable substitution asal_email2 UNIX for Dummies Questions & Answers 1 06-13-2005 09:35 PM
ksh substitution solea Shell Programming and Scripting 2 08-09-2004 02:30 AM
substitution supercbw Shell Programming and Scripting 1 06-07-2002 12:07 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #15  
Old 05-19-2007
Registered User
 

Join Date: Aug 2001
Posts: 58
Hi

I am even more confused regarding this regular expression

'.*/\(.*\)\..*'

can somebody please explain that.

I tried googling on this but that did not help much
Reply With Quote
Forum Sponsor
  #16  
Old 05-19-2007
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,611
Well maybe this will help... the pieces in red are special:
'.*/\(.*\)\..*'
They define the beginning and end of a saved field. This is what will be be returned. The stuff to letf of the saved field is .*/ which matches everything up to a slash. Inside the saved field we have .* which seems to say match any characters. But we can't match literally everything, we have to save (just) enough for the rest of the expression to work. So after the saved field we have \..* which says match a dot followed by any characters.
Reply With Quote
  #17  
Old 05-20-2007
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Milano, Italia/Варна, България
Posts: 1,855
Quote:
Originally Posted by aigles
[...]
works fine under zsh ( but i don't think that there is many people using this shell)
[...]
Yes,
unfortunately ...
Reply With Quote
  #18  
Old 05-22-2007
Registered User
 

Join Date: Aug 2001
Posts: 58
Quote:
Originally Posted by Perderabo
Well maybe this will help... the pieces in red are special:
'.*/\(.*\)\..*'
They define the beginning and end of a saved field. This is what will be be returned. The stuff to letf of the saved field is .*/ which matches everything up to a slash. Inside the saved field we have .* which seems to say match any characters. But we can't match literally everything, we have to save (just) enough for the rest of the expression to work. So after the saved field we have \..* which says match a dot followed by any characters.
Hi Perderabo

Thanks for the wunderful explanation

so what i understand is
.*/ Matches upto /
\(.*\) Matches and saves myfile.cd.070505123457
\..* Match a dot followed by any characters

So shouldnt this match just cd.070505123457 and the whole expression return myfile how come it is returning myfile.cd

Thanks for being so patient with me.

regards
Hrishy

Last edited by xiamin; 05-22-2007 at 11:46 PM.
Reply With Quote
  #19  
Old 05-23-2007
Ygor's Avatar
Moderator
 

Join Date: Oct 2003
Location: -31.96,115.84
Posts: 1,248
Regular expression quantifiers are greedy, so "*" means match as much as possible.

.*/ Matches any characters upto the last /
\(.*\)\. Matches and returns any characters upto the last .
.* not actually required. (I originally thought that this was required because expr regular expressions are anchored, but it turns out that they are only achored to the start of the expression.)
Reply With Quote
  #20  
Old 05-23-2007
Registered User
 

Join Date: Aug 2001
Posts: 58
Hi Ygor

Thanks ..a million i got it.

Gotta remember this "regular expressions are greedy "

regards
Hrishy
Reply With Quote
Google The UNIX and Linux Forums
Reply

Tags
regex, regular expressions

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:41 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