Wow. Problem resolved. The script is bulletproof. Thanks very much to both of you. Your gracious expertise has saved me a lot of time.
dp On Wednesday, March 22, 2023 at 4:58:07 PM UTC-5 Christopher Stone wrote: > 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/95dca53c-3b4f-4fa4-9482-12e1f2c85a30n%40googlegroups.com.
