3 # Split single text file with numbered sections into multiple files,
6 # Simple Bash script to add title to the resulting files:
8 # for i in `seq 1 350`; do
9 # sed -i '1s/^/The Storms of Chai\n/' $i.txt;
12 # See https://www.projectaon.org/en/Sanctum/Howto-proofread
16 use warnings qw< FATAL all >;
18 use Scalar::Util qw< openhandle >;
22 my $fh = new IO::Handle;
29 print STDERR "DEBUG: Reading '$line'\n" if $debug;
30 if ($line =~ /^(\d+)$/) {
32 $filename = "$section.txt";
33 print STDERR "DEBUG: Starting section $section\n" if $debug;
34 close $fh if $fh->opened();
35 open ($fh, ">>$filename") or die "Couldn't open file $filename, $!";
36 print $fh "Section $section\n";
39 # Print to the file if we have a filehandle except for the
40 # section number itself
41 if ($line !~ /^(\d+)$/) {
42 if ( $fh->opened() ) {
43 print STDERR "DEBUG: Printing to $filename\n" if $debug;
44 print $fh $line."\n" ;
50 close $fh if fileno($fh);