I have a 5000 lines file consisting of blocks of lines, with an END string between blocks, as follows
ATOM 1
ATOM 3
ATOM 25
END
ATOM 2
ATOM 36
ATOM 22
ATOM 12
END
ATOM 1
ATOM 87
END
I want to find a way to split the file into several files, each containing a single block of lines before the END string. The first file should look as follows:
ATOM 1
ATOM 3
ATOM 25
The second file should contain
ATOM 2
ATOM 36
ATOM 22
ATOM 12
And so on. I have thought of using something like awk '/END/{flag=1; next} /END/{flag=0} flag' file
to take the blocks between the END strings. This, however, does not work for my first block, as the END string is only after the block, and most importantly, cannot take into account the number of times it has found the string END to separate each block into its individual file.
Is there a way I can use the string END to split my file into several, each containing a block that ends with the string END?