Hi Peter -
You can do this with a text filter. Save the following code in a file
called something like "date_prefixer.pl", put it in your text filters
folder, then go back to your file and choose Text -> Apply Text Filter -
date_prefixer from the menubar.
What the script does:
1) Loops through each line in your selection (if you have one) or the
entire file (if you don't).
2) If the line starts with a word, followed by a space, followed by a
4-digit number, the value of the variable "$date" is set to the number,
plus a dash, plus the word, plus another dash.
3) If the line starts with "[play audio]", followed by a space, followed by
a two-digit number, the text "[play audio] " is replaced with the current
value of "$date", then the line is printed.
4) If neither match matches, then nothing is done and the script continues
on to the next line.
I set the script to do exactly what your example says. If you want it to
use the corresponding two-digit number for the month, change this line:
$date = $2 . "-$1-";
to
$date = $2 . "-$month{$1}-";
#!/usr/bin/perl
$month{"January"} = "01";
$month{"February"} = "02";
$month{"March"} = "03";
$month{"April"} = "04";
$month{"May"} = "05";
$month{"June"} = "06";
$month{"July"} = "07";
$month{"August"} = "08";
$month{"September"} = "09";
$month{"October"} = "10";
$month{"November"} = "11";
$month{"December"} = "12";
while (<>) {
if ( $_ =~ /^([^ ]+) ([0-9]{4})/ ) {
$date = $2 . "-$1-";
}
elsif ( $_ =~ /^\[Play Audio\] ([0-9]{2}.+)/i ) {
print $date . $1 . "\n";
}
}
On Thursday, April 30, 2020 at 3:13:04 PM UTC-4, Peter Kaufman wrote:
>
> Folks,
>
> I love BBEdit (v13.0.6) and hope this can do the trick! I would rather
> not have to resort to sed/awk/cut/paste.
>
> INPUT:
>
> April 2020
>
> (Individual talks will be added before the end of the month
> for a while.)
>
> [play audio] 25 Being Responsible
>
> [play audio] 24 In the Land of Wrong View
>
> [play audio] 05 Owners of Our Actions
>
> [play audio] 04 Wealth & Strength
>
> [play audio] 03 A Skillful Heart
>
> [play audio] 02 Stop & Think
>
> [play audio] 01 A Mirror for the Mind
>
> March 2020
>
> Full month zip
>
> [play audio] 31 Worry
>
> [play audio] 30 Put the Other Person’s Heart in Yours
>
> [play audio] 29 Protection Through Mindfulness
>
> [play audio] 28 Inner Worlds
>
> [play audio] 27 Four Mountains Moving In
>
> [play audio] 26 Interdependence
>
> [play audio] 25 Endurance & Contentment
>
> [play audio] 24 Alone Together
>
> [play audio] 23 Remembering Luang Lung
>
> [play audio] 12 Virtues and Values (Brazil)
>
> February 2020
>
> Full month zip
>
> [play audio] 16 Between Right & Wrong
>
> [play audio] 14 Know the Dhamma by Its Results
>
> [play audio] 13 The Third and a Half Noble Truth
>
>
>
> OUTPUT:
>
> Each [play audio] \d\d would be replaced with the previous YYYY-MONTH-\d\d
>
> e.g.
>
> 2020-April-25 Being Responsible
>
> : : :
>
> 2020-April-01 A Mirror for the Mind
>
> 2020-March-31 Worry
>
> : : :
>
>
>
>
>
> I know how to start this incantation:
>
> \W*(January|February|March|April|May|June|July|August|September|October|November|December)
>
> (\d\d\d\d)\n.*$(\W*\[play audio\] (\d\d) (.*$)){1,}
>
>
>
> But not how to do this. Are there variables one can assign within BBEdit?
> I hate to leave BBEdit in order to apply sed/awk/grep.
>
>
>
> Thanks in advance!!!
>
>
>
> Peter
>
>
>
--
This is the BBEdit Talk public discussion group. If you have a feature request
or need technical support, please email "[email protected]" rather than
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
---
You received this message because you are subscribed to the Google Groups
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/bbedit/e4716ad7-37b8-4119-8a15-5f77913b4863%40googlegroups.com.