How to match a pattern, delete the pattern and also the next and the previous line on Solaris 10

sedsolaristext processing

How can I match a pattern, delete the pattern and also the next and the previous line on Solaris 10?
I'm hiting the wall because Solaris does not come with GNU sed.
Given the following file content:

    LinearFile(3F007F106F3B, FDN, 29, 20)
    LinearFile(3F007F106F40, XXX, 29, 1)
    {
        LinearRec(1, 12345)
    }
    LinearFile(3F007F106F3C, SMS, 176, 20)
    LinearFile(3F007F106F4F, ECCP, 15, 10)
    LinearFile(3F007F106F40, XXX, 29, 1)
    {
      LinearRec(1, FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
    }
    LinearFile(3F007F106F42, SMSP, 43, 3)
    BinaryFile(3F007F106F43, SMSS, 2)
    LinearRec(1, 12345)

I would like to remove the block that contain:

    {
      LinearRec(1, FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)
    }

The file would be:

LinearFile(3F007F106F3B, FDN, 29, 20)
    LinearFile(3F007F106F40, XXX, 29, 1)
    {
        LinearRec(1, 12345)
    }
    LinearFile(3F007F106F3C, SMS, 176, 20)
    LinearFile(3F007F106F4F, ECCP, 15, 10)
    LinearFile(3F007F106F40, XXX, 29, 1)
    LinearFile(3F007F106F42, SMSP, 43, 3)
    BinaryFile(3F007F106F43, SMSS, 2)
    LinearRec(1, 12345)

To delete the next line I issued the following:

sed -e '/LinearRec(1\,\ FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF)/{n;d;}' file.txt

What about the line that matchs and the previous line?

Maybe it can be achieved by using ed or vi?
Thx!

Best Answer

A perl approach (assuming your file is small enough to load into memory):

perl -0pe 's/.+?\n.*?LinearRec\(1, F{58}\).*?\n.*?\n//' file

The -0 makes perl slurp the entire file, and the -p tells it to print each input line after applying the script given by -e. The script itself matches 58 Fs and the surrounding two lines and removes them.