LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   how to modify only the last part of the variable (https://www.linuxquestions.org/questions/linux-newbie-8/how-to-modify-only-the-last-part-of-the-variable-649927/)

pdklinux79 06-17-2008 11:52 AM

how to modify only the last part of the variable
 
here is a variable
$name=000000000002312.cdt

after using it in a process
then it is required by the program to change the variable
$name=000000000002312.wlg

how can it be accomplished , in bash shell script.

Thank you

pdklinux79 06-17-2008 11:54 AM

Another Note: the variable when assinged first is an user input.. after that, we need it to change only the extensions.. i dont know how to do it..

colucix 06-17-2008 12:06 PM

Code:

name=${name/%cdt/wlg}
this substitutes the substring "cdt" that matches at the back end of the string.

pdklinux79 06-17-2008 12:10 PM

Thank you . It is working.. am a newbie.. Appreciate ur prompt help..


All times are GMT -5. The time now is 10:49 PM.