Hello
One question. Are you sure what you want is this:
C09E01 _Script Updates_ Creating Stripts
C09E02 _Script Updates_ Exporting scripts
C09E03 _Script Updates_ Previewing your script
C11E01 _Actual Working Script_ Work Practices
C11E02 _Actual Working Script_ Work scripts
and NOT this:
C09E01 _Script 2015 Updates_ Creating Stripts
C09E02 _Script 2015 Updates_ Exporting scripts
C09E03 _Script 2015 Updates_ Previewing your script
C11E01 _Actual Working Script_ Work Practices
C11E02 _Actual Working Script_ Work scripts
?
* I presumed C10E01 and C10E02 should read C11E01 and C11E02 respectively.
Assuming the answer is yes, here's a perl script you may try:
#!/bin/bash
perl -CSDA -w <<'EOF' - in.txt > out.txt
use strict;
my %h = ();
my $c = 0;
while (<>) {
chomp;
$c = $1 if / ^([0-9]+) \. \s /ox and $1 != $c;
push @{$h{$c}}, $_ if $c and not /(?:[0-9]+(h|m|s)){1,3}/;
}
for my $k (sort {$a <=> $b} keys %h) {
# (my $t = $h{$k}->[0]) =~ s/ ^[0-9]+ \. \s+ //ox; # remove leading /[0-9]+\.\s+/
(my $t = $h{$k}->[0]) =~ s/ [0-9]+ \.? \s+ //ogx; # remove every /[0-9]+\.?\s+/
for my $i (1 .. @{$h{$k}} - 1) {
printf qq(C%02dE%02d _%s_ %s\n), $k, $i, $t, $h{$k}->[$i];
}
}
EOF
And an AppleScript wrapper of it:
set infile to (choose file of type {"txt"} with prompt "Choose input text file")'s POSIX path
set outfile to (choose file name default name "out.txt" with prompt "Choose output text file name and location")'s POSIX path
do shell script "perl -CSDA -w <<'EOF' - " & infile's quoted form & " > " & outfile's quoted form & "
use strict;
my %h = ();
my $c = 0;
while (<>) {
chomp;
$c = $1 if / ^([0-9]+) \\. \\s /ox and $1 != $c;
push @{$h{$c}}, $_ if $c and not /(?:[0-9]+(h|m|s)){1,3}/;
}
for my $k (sort {$a <=> $b} keys %h) {
# (my $t = $h{$k}->[0]) =~ s/ ^[0-9]+ \\. \\s+ //ox; # remove leading /[0-9]+\\.\\s+/
(my $t = $h{$k}->[0]) =~ s/ [0-9]+ \\.? \\s+ //ogx; # remove every /[0-9]+\\.?\\s+/
for my $i (1 .. @{$h{$k}} - 1) {
printf qq(C%02dE%02d _%s_ %s\\n), $k, $i, $t, $h{$k}->[$i];
}
}
EOF"
Hope this may help,
H