Shell string processing using regex and extract words based on delimiters -
i have asked question using regex string last colon. have received answers though don't quite know how integrate rest of program. have command line return output in form of st:st:st:st1-st2-st3-st4-...stn
, want strip out st1, st2, st3...stn , write them in text file st1 \n "st2 \n...."stn \n
.
i know can use while ifs:-
extract strings want how rid of string before last colon?
how rid of string before last colon?
use prefix removal:
$ str='st:st:st:st1-st2-st3-st4-...stn' $ echo "${str##*:}" st1-st2-st3-st4-...stn
${str##*:}
returns string $str
after having removed longest match starts beginning , ends :
.
documentation
from man bash
:
${parameter#word}
${parameter##word}
remove matching prefix pattern. word expanded produce pattern in pathname expansion. if pattern matches beginning of value of parameter, result of expansion expanded value of parameter shortest matching pattern (the ''#'' case) or longest matching pattern (the ''##'' case) deleted. if parameter @ or *, pattern removal operation applied each positional parameter in turn, , expansion resultant list. if parameter array variable subscripted @ or *, pattern removal operation applied each member of array in turn, , expansion resultant list.
Comments
Post a Comment