Shell deleting specific lines

Hi,

I'am working under unix solaris

I have a text file with set of lines, each set of lines (BLOCK) have
three fixed lines :

Between SECND line and THEND we have N lines, N differ from a block to another

sample :

i have to make a script wich delete each 3 fixed lines if N=0 (no lines between SECND end THEND line) :
delete every set of this three sucessive lines (FIRST SECND THEND)
FIRST0873HGGD EE 889
SECNDKIIKIE 99099 88 7 DDSFF 000999999
THEND

sample :
before the script i have this text file

after the script i will have :

thanks a lot for your help

May not be the most 'compact' code, but it will work:

#!/usr/bin/env ksh

awk '
        /^FIRST/ {         # hold first/second lines until we have a "body"
                first = $0;
                snarf = 0;
                next;
        }
        /^SECND/ {
                second = $0;
                next;
        }

        /^THEND/ {
                if( snarf )        # if we printed a body, safe to print last line
                        printf( "%s\n", $0 );
                snarf = 0;
                next;
        }

        {
                if( ! snarf )         # print first/second lines on first line of body
                        printf( "%s\n%s\n", first, second );
                printf( "%s\n", $0 );

                snarf = 1;
        }
' <input-file

Simple code with little bug.

awk 'BEGIN{RS=ORS="FIRST";FS="\n"} NF>4' infile

0873HGGD EE 889
SECNDKIIKIE 99099 88 7 DDSFF 000999999
7888DUBN998FFFFFFFFFF
6666FFDD 88 RFR 88888 0000R YJ
THEND
FIRST0873HGGD EE 889
SECNDKIIKIE 99099 88 7 DDSFF 000999999
7333DUBN998FFFFFFFFFF
5688DUBN998FFFFFFFFFF
7777FFDD 88 RFR 88888 0000R YJ
THEND
FIRST0873HGGD EE 889
SECNDKIIKIE 99099 88 7 DDSFF 000677999
4444DUBN998FFFFUUUF
7777FFDD 88 RFR 88888 0000R YJ
THEND
FIRST

you need manually move the last FIRST to the beginning of the output.

agama and rdcwayx, thanks for your answers, sorry for my late answer

I will test the code of agama, because it hasn't a bug