You may also use the Unix text editor ed:
echo '
pattern1
garbage
pattern2
' > test.txt
cat <<-'EOF' | sed -e 's/^ *//' -e 's/ *$//' | ed -s test.txt &>/dev/null
H
/pattern1/+1,/pattern2/-1d
wq
EOF
For more information see: Editing files with the ed text editor from scripts