Artificial intelligent assistant

How to split a file into multiple file after N appearence of a pattern? I have a file on Linux, containing the coordinates of thousands of molecules. Each molecule starts with a line containing always the same pattern: @<TRIPOS>MOLECULE And then continues with other lines. I would like to split the file into multiple files, each containing a certain number of molecules. What is the easiest way to do this?

One way is to use `awk`:


awk -v moleculesNum=7 '
/^@MOLECULE/{
if((++num)%moleculesNum==1){
close(outfile); outfile="file" (++Output)
}
}
{ print >outfile }' infile


this splits the original file into multiple files each having maximum 7 number of MOLECULEs (adjustable in `moleculesNum=7` parameter)

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 185453049c6222521f56d25c1b8ff9c0