LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   bash string processing (https://www.linuxquestions.org/questions/programming-9/bash-string-processing-537226/)

powah 03-13-2007 06:56 PM

bash string processing
 
If the bash input parameter $1 is in the format "xyznnnnn", where "xyz" is fixed and "nnnnn" can be varied, how to extract the remaining of the string "nnnnn"?
e.g.
If input is "xyzabc", then extracted string should be "abc".
If input is "xyz12345678", then extracted string should be "12345678".
Thanks in advance.

ghostdog74 03-13-2007 07:02 PM

you can read about bash string processing here

jlinkels 03-14-2007 06:13 AM

stripped_string=$(echo $1 | sed s/xyz//)

This is what I could do without looking it up in the Bash guide. Bash also has string functions. Take a look at the guide as pointed to in my signature.

jlinkels

bigearsbilly 03-14-2007 06:40 AM

Code:

bash-2.05$ x=xyz12345   
bash-2.05$ echo $x
xyz12345
bash-2.05$ echo ${x#xyz}
12345



All times are GMT -5. The time now is 08:14 AM.