Print the first n line in each section

Hi,
i have a file like this:

...
11111111
22222222
33333333
#
4444444
5555555
6666666
7777777
#
...

i want just print the 2 first line between each section (each section is separated with "#"). so desired output would be like this:

...
11111111
22222222
#
4444444
5555555
#
...

i wrote this code, but it doesn't work!

awk 'BEGIN{RS="#";FS="\n"}{print $1,$2}' in > out
awk '/^#/{print;c=0}c<2&&!/^#/{print;++c;}' filename
1 Like

it works perfectly, thank you

Elaborating on the OP's original idea

awk '{sub(/^\n/,x); print $1,$2}' RS=# FS='\n' OFS='\n' file

sed variation of the idea of making an exception for the first record

sed -n '1,2p; /#/{n;N;p;}'