Selectively splitting a file with C-shell?

I have a rather long csh script that works, but it's terribly ungraceful and takes a while from various loops. I only know enough code to get myself into trouble, so I'm looking for some guidance.

I have a large file that is separated at intervals by the same line, like this:

@<TRIPOS>molecule
name_000
blah
yadda
stuff
@<TRIPOS>molecule
name_001
blah2
yadda2
stuff2
@<TRIPOS>molecule
name_002
blah3
...

and so on for up to name_200, where blah/yadda/stuff are strings with numbers, letters, and white spaces.

I need to split this file into individual files, named name_000.mol2, name_001.mol2, name_002.mol2 etc, each of which contain:

@<TRIPOS>molecule
name_000 (or name_whatever)
blah
yadda
stuff

Currently I grep -n 'TRIPOS>molecule' the big file into another file, then use the line numbers to cycle through and pull out lines x through y, naming each file based on what's in line x+1 (name_000), with .mol2 on the end. This takes an incredibly long time, and is rather clunky. I don't know if it's the file cycling or all the variables I pass back and forth that eats up the time, but if anyone knows of an easier way to split the big file up, I would greatly appreciative!

I can't come up with a good way to do this in awk - the line numbers between each TRIPOS>molecule are variable, and my awk-fu is rather weak. I also need to keep this in CSH or I'll have to convert a ton of other code.

Any ideas?

Thanks!

Hi.

Does your system have commands csplit or split (with -p pattern)? ... cheers, drl

It does! I've never seen that before - I'll have to investigate.

Thanks!