![]() |
|
|
|
|
|||||||
| 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 | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Double Substitution variables in ksh
Hi
I have a variable whose value is like this i=/test/test1/test2/myfile.cd.070505123457 i would like to have the value of myfile.cd stored into another variable my attempt is test=${i##*/} ;echo $test ##and i get myfile.cd.070505123457 since what i wnat is myfile.cd i try this test={{${i##*/}}##.} ;echo $test and i get an error Any idea how do i get what i want ? regards xiamin |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
Code:
i=/test/test1/test2/myfile.cd.070505123457
test=${i##*/}
test=${test%.*}
|
|
#3
|
|||
|
|||
|
Hi Anbu
Thanks for your reply I was wundering if we could do that in one line regards xiamin |
|
#4
|
||||
|
||||
|
Try...
Code:
test=$(expr $i : '.*/\(.*\)\..*') |
|
#5
|
|||
|
|||
|
Hi Ygor
Your solution works like charm.. But now i am pulling my hair out trying to understand what magic your code tries to do... Can you please explain or else i might go bald :-) regards Hrishy |
|
#6
|
||||
|
||||
|
Quote:
Code:
i=/test/test1/test2/myfile.cd.070505123457 ; test=${i##*/} ; test=${test%.*}
|
|
#7
|
|||
|
|||
|
Hi Perderabo
Your welcome :-) Sometimes we are tempted and take the bait ;-).I guess you are seduced by unix regards Hrishy |
|||
| Google The UNIX and Linux Forums |
| Tags |
| regex, regular expressions |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|