Split a file based on a pattern

Dear all,

I have a large file which is composed of 8000 frames, what i would like to do is split the file into 8000 single files names file.pdb.1, file.pdb.2 etc etc

each frame in the large file is seperated by a "ENDMDL" flag so my thinking is to use this flag a a point to split the files up. however im having great dificulty in trying to output each frame to a new file in perl? suggetsions and help will be much appreciated.

example of the large file

ENDMDL
mpla
mpla ok ok ,pla mpla mpla
mpla 
mpla
ENDMDL
mpla2 mpla2 mpla2 mpla2
mpla2 mpla2 
mpla2 mpla2
ENDMDL
mpla
 mpla ok ok ,pla mpla mpla
 mpla 
 mpla
 ENDMDL
 mpla2 mpla2 mpla2 mpla2
 mpla2 mpla2 
 mpla2 mpla2
 ENDMDL

MISH

Try this:

awk '/ENDMDL/{i++}{print > "file.pdb."i}' file
1 Like

Cool...

Hi Franklin52,
This works really well and its pretty quick.

Mish

you can use below to set 'ENADMDL' as the line seperator instead of use the default '\n'

$/="ENDMDL";