Interesting problem; I’m also curious about this.
Unfortunately I don’t have an answer, but this reminds me of a related problem I had with splitting a text file into multiple files based on context lines. Maybe it can trigger some thoughts.
I had a file,contours, like this (from gmt):
>
462365 3685357
857483 4869490
576857 4657687
645342 6879576
>
657483 7584930
657483 3746584
....
And wanted each segment (separated by >) to be in individual files.
Here I could use csplit(1):
$ csplit --elide-empty-files --quiet --prefix=split_ contours "/>/0" "{*}"
$ ls
contours split_00 split_01
$ cat split_00
>
462365 3685357
857483 4869490
576857 4657687
645342 6879576
$ cat split_01
>
657483 7584930
657483 3746584
....