#!/bin/bash
str ="$(echo -e "abcde\n fghij<FooBar>") " ;
echo "----- sed ------"
sed 'H;1h;$!d;x; s/\(.*\)><Foobar>/\1/' <<< "$str "
# Remove lines between two matching lines including them:
sed '/^start;/,/^end;/d' <<< "$(echo -e "Here:\nstart;more text\nText... here\nend; and\nEnd of string.") "
# Remove lines between two matching lines excluding them:
sed '/^start;/,/^end;/{{//!d;};}' <<< "$(echo -e "Here:\nstart;more text\nText... here\nend; and\nEnd of string.") "
echo "----- Perl ------"
perl -0pe 's/(.*)<FooBar>/$1/gs' <<< "$str "
echo "----- GNU grep ------"
grep -Poz '(?si)abc\K.*?(?=<Foobar>)' <<< "$str "
IyEvYmluL2Jhc2gKc3RyPSIkKGVjaG8gLWUgImFiY2RlXG4JCWZnaGlqPEZvb0Jhcj4iKSI7CmVjaG8gIi0tLS0tIHNlZCAtLS0tLS0iCnNlZCAnSDsxaDskIWQ7eDsgcy9cKC4qXCk+PEZvb2Jhcj4vXDEvJyA8PDwgIiRzdHIiCiMgUmVtb3ZlIGxpbmVzIGJldHdlZW4gdHdvIG1hdGNoaW5nIGxpbmVzIGluY2x1ZGluZyB0aGVtOgpzZWQgJy9ec3RhcnQ7LywvXmVuZDsvZCcgPDw8ICIkKGVjaG8gLWUgIkhlcmU6XG5zdGFydDttb3JlIHRleHRcblRleHQuLi4gaGVyZVxuZW5kOyBhbmRcbkVuZCBvZiBzdHJpbmcuIikiCiMgUmVtb3ZlIGxpbmVzIGJldHdlZW4gdHdvIG1hdGNoaW5nIGxpbmVzIGV4Y2x1ZGluZyB0aGVtOgpzZWQgJy9ec3RhcnQ7LywvXmVuZDsve3svLyFkO307fScgPDw8ICIkKGVjaG8gLWUgIkhlcmU6XG5zdGFydDttb3JlIHRleHRcblRleHQuLi4gaGVyZVxuZW5kOyBhbmRcbkVuZCBvZiBzdHJpbmcuIikiCgplY2hvICItLS0tLSBQZXJsIC0tLS0tLSIKcGVybCAtMHBlICdzLyguKik8Rm9vQmFyPi8kMS9ncycgPDw8ICIkc3RyIgoKZWNobyAiLS0tLS0gR05VIGdyZXAgLS0tLS0tIgpncmVwIC1Qb3ogJyg/c2kpYWJjXEsuKj8oPz08Rm9vYmFyPiknIDw8PCAiJHN0ciI=