X-Git-Url: http://git.projectaon.org/?p=project-aon.git;a=blobdiff_plain;f=common%2Fscripts%2Fsplit-sections.pl;h=1c1c8b8b7dfa6b0460c4893013d5067861785d61;hp=59ceef4c81c68bd5cbd2638d237459c6f5dfb90d;hb=f90cf1eea570aacdee9c831c498ad35aef0768c4;hpb=b6f6c3d13b44f069d1b947aa7266360cbeb6eba1 diff --git a/common/scripts/split-sections.pl b/common/scripts/split-sections.pl index 59ceef4..1c1c8b8 100755 --- a/common/scripts/split-sections.pl +++ b/common/scripts/split-sections.pl @@ -1,4 +1,15 @@ -#!/bin/env perl +#!/usr/bin/env perl +# +# Split single text file with numbered sections into multiple files, +# one per section. +# +# Simple Bash script to add title to the resulting files: +# +# for i in `seq 1 350`; do +# sed -i '1s/^/The Storms of Chai\n/' $i.txt; +# done +# +# See https://www.projectaon.org/en/Sanctum/Howto-proofread use strict; use autodie; @@ -13,7 +24,7 @@ my $line = ""; my $section = ""; my $filename = ""; -while ($line = ) { +while ($line = <>) { chomp ($line); print STDERR "DEBUG: Reading '$line'\n" if $debug; if ($line =~ /^(\d+)$/) { @@ -21,7 +32,8 @@ while ($line = ) { $filename = "$section.txt"; print STDERR "DEBUG: Starting section $section\n" if $debug; close $fh if $fh->opened(); - open ($fh, ">>$filename") or die "Couldn't open file $filename, $!" + open ($fh, ">>$filename") or die "Couldn't open file $filename, $!"; + print $fh "Section $section\n"; } # Print to the file if we have a filehandle except for the