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
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