Thank you, Bob. Both work great for me.
Bob Proulx wrote: > > maybee wrote: >> >> I have a string mq001234ms00567_b3.45_323x7, >> and I want to subtract the numbers from it, that is, >> I will get >> mq=001234 >> ms=00567 >> b=3.45 >> >> These number may have various digits. >> Any neat way doing this under bash? > > I myself would use 'sed' (because I always have): > > x=mq001234ms00567_b3.45_323x7 > > mq=$(echo "$x" | sed 's/mq\([[:digit:]]*\).*/\1/') > echo "$mq" > 001234 > > ms=$(echo "$x" | sed 's/.*ms\([[:digit:]]*\).*/\1/') > echo "$ms" > 00567 > > b=$(echo "$x" | sed 's/.*_b\([0-9][0-9]*[.][0-9][0-9]*\).*/\1/') > echo "$b" > 3.45 > > But it certainly seems reasonable to use the bash parameter expansion > methods to do something similar. > > $ echo ${x%%ms*} > mq001234 > > But my brain doesn't think that way and so I didn't work up a full > procedure. > > Bob > > > > -- View this message in context: http://www.nabble.com/Problem%3A-extracting-substring-tp19749658p19764513.html Sent from the Gnu - Bash mailing list archive at Nabble.com.