in reply to split of files

So you want to set the file boundary to just before "INPUT SEQUENCE"?

There Is More Than One Way To Do It - one bizarre way is

#!/usr/bin/perl { local $/ = "INPUT SEQUENCE="; <>; # discard first chunk while(<>) { chomp; open O, '>', /^(\d+)/ and $1 or die "$!\n"; print O $/,$_; } }

update - oh. You want bunches of 1000 records in separate files?

#!/usr/bin/perl { my $file = 'File00000'; local $/ = "INPUT SEQUENCE="; <>; while(<>) { chomp; unless ($.-2 % 1000) { open O, '>', ++$file or die "cant write '$file': $!\n"; } print O $/,$_; } }

update - a bit of explanation: setting the input record separator $/ (see perlvar) to the token right after the file boundary lets the diamond operator <> (or readline) read up to and including that token as a single line into $_.

With chomp we remove $/ from the end; it is added up front when outputting. The ++$file is a string increment; doing that we get the next file name (File00001, File00002, ... ).

Since the first "line" (consisting of the record separator only) isn't interesting, we do a <> before the loop. Next line is then number 2 ($. - see perlvar), and $.-2 % 1000 (modulo 1000) is 0 at line 2, 1002, 2002, ... , so we (re-)open the output filehandle at that line count, which does an implicit close. See open.

--shmem

_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}