search and retrieve previous line in file

I've got a file with the following layout:

#STMP FSgroup
filename /filesysname1
filestatus 2

#STMP FSstatus
filename /filesysname1
ratio 30

#STMP FSgroup
filename /filesysname1
filestatus 2

#STMP FSstatus
filename /filesysname6
ratio 60

I'm trying to write a SHELL (ksh) script that'll search the file say e.g filename = /filesysname1 grouped under FSstatus and get everthing beneath FSstatus group.

Thus, I should be able search for anygroup, i.e. lines that start with an # and everything below it until the first blank line. I also need to know the group name, i.e. either FSstatus or FSgroup

Look really difficult for me, any help out there

tks
William :frowning:

Will this be ok?

var=filesysname1
awk -F" " 'BEGIN{group=""; x=0} { if( x == 1 ) { print } if( $0 ~ /^#/) { group = $0; next } if( $0 ~ /'$var'/ ) { x=1; print group; print $0} else { x = 0 } }' file

If all the groups are separated by blank line you can use this

awk -v RS="" -v FS="\n" -v ORS="\n\n" ' $1 ~ "FSstatus" && $0 ~ "/filesysname1" ' file

If all the groups are separated by blank line you can use this to display group with group name "FSstatus"

awk -v RS="" -v FS="\n" -v ORS="\n\n" ' $1 ~ "FSstatus" ' file