![]() |
|
|
|
|
|||||||
| 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 |
| 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 |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
#15
|
|||
|
|||
|
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 |
| Forum Sponsor | ||
|
|
|
#16
|
||||
|
||||
|
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. |
|
#17
|
||||
|
||||
|
Quote:
unfortunately ... |
|
#18
|
|||
|
|||
|
Quote:
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. |
|
#19
|
||||
|
||||
|
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.) |
|
#20
|
|||
|
|||
|
Hi Ygor
Thanks ..a million i got it. Gotta remember this "regular expressions are greedy " regards Hrishy |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | |
| Display Modes | |
|
|