Help needed in removing intermediate segments from a pipe delimited segment file

Hi,

I just stuckup in doing some regular expressions on a file.

I have data which has multiple FHS and BTS segments like:

FHS|12121|LOCAL|2323
MSH|10101|POTAMAS|2323
PID|121221|THOMAS|DAVID|23432
OBX|2342|H1211|3232
BTS|0000|MERSTO|LIABLE
FHS|12121|LOCAL|2323
MSH|10101|POTAMAS|2323
PID|121221|THOMAS|DAVID|23432
OBX|2342|H1211|3232
BTS|0000|MERSTO|LIABLE
FHS|12121|LOCAL|2323
MSH|10101|POTAMAS|2323
PID|121221|THOMAS|DAVID|23432
OBX|2342|H1211|3232
BTS|0000|MERSTO|LIABLE

I am trying to have an output which will have only one FHS at the beginning and one BTS in the ending.
And all other FHS and BTS in the middle should be deleted.

The output should look like :

FHS|12121|LOCAL|2323
MSH|10101|POTAMAS|2323
PID|121221|THOMAS|DAVID|23432
OBX|2342|H1211|3232
MSH|10101|POTAMAS|2323
PID|121221|THOMAS|DAVID|23432
OBX|2342|H1211|3232
MSH|10101|POTAMAS|2323
PID|121221|THOMAS|DAVID|23432
OBX|2342|H1211|3232
BTS|0000|MERSTO|LIABLE

I will be glad if you give me some light in solving this problem.

Thanks in advance.

Naren

grep -v "^BTS" input_file > ouptput_file
grep "^BTS" input_file >> output_file

sed -e '/^BTS/{$!d;}' -e '/^FHS/{1!d;}'

nawk 'NR == 1' input_file > output_file
grep -v "^FHS" input_file > pp | grep -v "^BTS" pp >> output_file
Q=wc -l input_file
nawk 'NR == $Q' input_file >> output_file