Help with an (easy) parser

Hello, i'm workig with a file with structural information about biological macromolecules (proteins etc).

In a certain file, the info is structured like this

@<TRIPOS>MOLECULE
blah 1
blah 2
blah 3
@<TRIPOS>MOLECULE
foo 1
foo 2
foo 3
@<TRIPOS>MOLECULE
mmm 1
mmm 2
mmm 3

I would like to slipt the info in a file for each @<TRIPOS>MOLECULE entry

File 1:
@<TRIPOS>MOLECULE
blah 1
blah 2
blah 3

File 2:
@<TRIPOS>MOLECULE
foo 1
foo 2
foo 3

etc etc

How could be the best way to implement this parser?. Could anybody show me an example with something similar, please, to write my own parser?

Thank you in advanced!!! best regards.

1) what to call the filenames? is it part of the text already in the file? Or simply file_0001 then file_0002 then ....
2) will it always be three lines of data for each file?

1) OK, is interesting for me that, if the name of the original file is
my_file.mol2

the name of the new files must be
new_file1.mol2 etc etc
new_fiile2.mol2 etc etc

2) No, the information is dinamic, the number of lines between each @<TRIPOS>MOLECULE is not constant.

A "real" example:

@<TRIPOS>MOLECULE
core; [Isoc-015]
41 42 2
SMALL
NO_CHARGES
(...)
@<TRIPOS>MOLECULE
core; [Isoc-167]
41 41 2
SMALL
NO_CHARGES
(...)

Thankx!!!

awk '/@<TRIPOS>MOLECULE/{k="new_file"n+1"."FILENAME;close(k);f=0;print "@<TRIPOS>MOLECULE" > k} f{print > k} /@<TRIPOS>MOLECULE/{f=1;n++}' my_file.mol2

> cat in_file
@<TRIPOS>MOLECULE
core; [Isoc-015]
41 42 2
SMALL
NO_CHARGES
(...)
@<TRIPOS>MOLECULE
core; [Isoc-167]
41 41 2
SMALL
NO_CHARGES
(...)
@<TRIPOS>MOLECULE
core; [Isoc-085]
41 42 2
SMALL
NO_CHARGES
(...)
@<TRIPOS>MOLECULE
core; [Isoc-267]
41 41 2
SMALL
NO_CHARGES
(...)
> cat mk_file
#! /usr/bin/bash
#
# reads in_file
# creates sequentially numbered output files

count=0000
out_f="molecule"
while read zf
   do
   char1=$(echo "$zf" | cut -c1)
   if [ $char1 = "@" ]
      then
      count=$((count+1)) 
      countt=$(printf "%.4d" "$count")
      out_file="$out_f""$countt"
   fi
   echo $countt "$zf"
   echo "$zf" >>$out_file 
done<in_file

Program execution displays progress and builds files

> ls molecule*
molecule0001  molecule0002  molecule0003  molecule0004

Note that I designed to count from 0001 to 9999 for molecule filenames.

I'm trying to use csplit, LibDav.mol2 is the original file

csplit -k -f LibDav LibDav.mol2 %@\<TRIPOS\>MOLECULE%

but LibDav00 and LibDav.mol2 are the same file. Any suggestions? Thank you in advanced.

if its too long, break and indent them. for the benefit of readability

You are getting the correct result according to what you have told csplit to do. Try the following if you are using the GNU version of csplit

csplit -k -f LibDav LibDav.mol2 /@<TRIPOS>MOLECULE/  {*}

Otherwise you need to tell csplit how many times to repeat the pattern e.g.

csplit -k -f LibDav LibDav.mol2 /@<TRIPOS>MOLECULE/  {24}