Q: Correcting Text Document for a file list
I've decided to post a fresh request, as I figure this should be possible but is currently beyond me.
I have some videos that I need renaming, but my lists need organising first.
Here is the Input text and output text that I would like to achieve via scripting/terminal commands.
I figure there isn't the need to use excel all the time for something like this. Thus relies on less power being used to do so.
Many thanks in advance to anyone that can help.
Matt
| Input Text file | Output Text File |
|---|---|
Introducing Scripts 1m 19s 9. Script 2015 Updates 1h 23m Creating Stripts 10m 57s Exporting scripts 4m 49s Previewing your script 4m 11s 11. Actual Working Script 1h 23m Work Practices 5m 43s Work scripts 2m 1s | C09E01 _Script Updates_ Creating Stripts C09E02 _Script Updates_ Exporting scripts C09E03 _Script Updates_ Previewing your script C10E01 _Actual Working Script_ Work Practices C10E02 _Actual Working Script_ Work scripts |
iMac, OS X Mavericks (10.9.4)
Posted on Oct 9, 2015 12:38 PM
Oops. The previous time code (1h 2m 3s etc) detection pattern is not so precise. Here's correction.
- perl script in shell
#!/bin/bash
perl -CSDA -w <<'EOF' - in.txt > out.txt
use strict;
my %h = ();
my $c = -1;
while (<>) {
chomp;
$c = $1 if / ^([0-9]+) \. \s /ox and $1 != $c;
push @{$h{$c}}, $_ if ($c >= 0) and not /^(?:[0-9]+(h|m|s) *){1,3}$/; # CORRECTED
}
for my $k (sort {$a <=> $b} keys %h) {
(my $t = $h{$k}->[0]) =~ s/ ^[0-9]+ \. \s+ //ox; # remove leading /[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
- applescript wrapper
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 = -1;
while (<>) {
chomp;
$c = $1 if / ^([0-9]+) \\. \\s /ox and $1 != $c;
push @{$h{$c}}, $_ if ($c >= 0) and not /^(?:[0-9]+(h|m|s) *){1,3}$/; # CORRECTED
}
for my $k (sort {$a <=> $b} keys %h) {
(my $t = $h{$k}->[0]) =~ s/ ^[0-9]+ \\. \\s+ //ox; # remove leading /[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"
Cheers,
H
Posted on Oct 11, 2015 3:38 AM