A purely bash solution, requires two steps to strip prefix & suffix separately (but probably runs faster, because no subprocesses):
#!/bin/bash
orig='from=someuser@somedomain.com, '
one=${orig#*from=}
two=${one%,*}
printf "Result:\n"
printf "$orig\n"
printf "$one\n"
printf "$two\n"
Output:
Result:
from=someuser@somedomain.com,
someuser@somedomain.com,
someuser@somedomain.com
Notes:
${var#*pattern}
using #
strips from the start of $var
up to pattern
${var%pattern*}
using %
strips from end of $var
, up to pattern
- similar could be accomplished with
${var/pattern/replace}
(and leaving replace
blank), but it's trickier since full regexp isn't supported (ie, can't use ^
or '$'), so you can't do (for example) /^from=//
, but you could do in step one ${var/*from=/}
and then in step two, do ${var/,*/}
(depending on your data, of course).
- see also: http://www.tldp.org/LDP/abs/html/parameter-substitution.html