Bash makes things simple with parameter expansions that allow trimming from the front (beginning) or back (end) of a string. For example:
s="lorem ipsum dolor: sit amet" ## full string
b="${s##*dolor: }" ## remove everything from front through "dolor: "
a="${s% $b}" ## remove everything saved in $b from back + space
Example:
s="lorem ipsum dolor: sit amet"
b="${s##*dolor: }"
a="${s% $b}"
printf "a: %s\nb: %s\n" "$a" "$b"
a: lorem ipsum dolor:
b: sit amet
Where $a
and $b
contain the desired strings. The parameter expansions can be found in man bash
but the ones to trim from front or back are summarized as:
${var#pattern} Strip shortest match of pattern from front of $var
${var##pattern} Strip longest match of pattern from front of $var
${var%pattern} Strip shortest match of pattern from back of $var
${var%%pattern} Strip longest match of pattern from back of $var
(note: pattern can contain the normal globbing characters such as '*'
)
Let me know if you have further questions.