> On Mar 22, 2023, at 10:40, Doug Pinkerton <[email protected]> wrote:
>
> I need to convert data formatted for humans into data formatted for a
> database. The actual document is subject to privacy regulation. The following
> is a mockup to illustrate the task. I need to convert this:
Hey Doug,
Here's a Perl filter that will do the job.
-Chris
#!/usr/bin/env perl -0777 -nsw
# ------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2023/03/22 16:51
# dMod: 2023/03/22 16:51
# Task: Reformat Data for Use in a Database.
# Tags: @ccstone, @Shell, @Script, @Reformat, @Data, @Database
# ------------------------------------------------------------
use v5.12;
$_ =~ s!\A\s+|\s+\Z!!g;
my @recordArray = split(/\n\n/, $_);
foreach my $record (@recordArray) {
my @record = split(/\n/, $record);
my $line1 = $record[0];
$line1 =~ s!^(.+)\h?-.+!$1!;
my $line2 = $record[1];
$line2 =~ s!^(\w+)\h.+!$1!;
my $prefix = $line1 . "\t" . $line2;
my $recordLength = scalar(@record) - 1;
my @newRecord = @record[2 .. $recordLength];
foreach my $recordItem (@newRecord) {
say $prefix . "\t" . $recordItem;
}
}
--
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/7DAFE8F0-A39B-4593-A7D6-E1491F03B680%40gmail.com.