You could try this :
sed -n -e '/^#$/!d
:loop
n
/^#$/q
p
b loop' program.sh
or, as a one-liner:
sed -n -e '/^#$/!d; :loop; n; /^#$/q; p; b loop' program.sh
Explanations:
/^#$/!d .--------------------------------------------------.
| if the current line does not consist in a single |
^ | hash , delete it and start a new cycle |
| .--------------------------------------------------.
| |
|______________________________________/
At this point, the current line is composed of a single hash.
:loop -----------------> define loop label
^ n -------------> replace current line by next line
|
| /^#$/q --------> quit if we've found the second hash marker
|
| p -------------> otherwise print current line
|
| b loop
| |
|_______/
UPDATE:
Perhaps I misunderstood your question. If what you need is to print a series of several blocks of instructions delimited by single hash markers, like this :
# blah blah #
Foo bar stuff thing
Lorem ipsum abracadabra ...
#
code1 start
code1
code1
code1
code1
code1
code1 end
#
Foo bar stuff thing
Lorem ipsum abracadabra ...
#
code2 start
code2
code2
code2
code2
code2
code2
code2
code2
code2 end
#
Foo bar stuff thing
Lorem ipsum abracadabra ...
#
code3 start
code3
code3
code3
code3 end
#
Foo bar stuff thing
Lorem ipsum abracadabra ...
then you can simply trade the "q" SED command for a "d" :
/^#$/!d
:loop
n
/^#$/d
p
b loop
Then, sed -n -e '/^#$/!d; :loop; n; /^#$/d; p; b loop' program.sh
would return (based on the above data sample) :
code1 start
code1
code1
code1
code1
code1
code1 end
code2 start
code2
code2
code2
code2
code2
code2
code2
code2
code2 end
code3 start
code3
code3
code3
code3 end