> On Sep 08, 2021, at 10:05, Howard <[email protected]> wrote:
> I have multiple instances of this sample data (below) in which each 
> observation has at least three lines and is separated by a blank line. In 
> each observation, the first line contains a name, the second a time, and then 
> there is one or more lines of text:


Hey Howard,

This is a bit of a chore but not uber difficult using a Perl text filter.


--
Best Regards,
Chris


#!/usr/bin/env perl -0777 -nsw
# -------------------------------------------------------------
# Auth: Christopher Stone <[email protected]>
# dCre: 2021/09/08 15:31
# dMod: 2021/09/08 15:31 
# Task: Concatenate Data Records and Count Same-Name-Keys.
# Tags: @ccstone, @Shell, @Script, @Perl, @Howard, @BBEdit-Talk
# -------------------------------------------------------------

# Trim vertical leading and trailing whitespace.
s!\A\s+|\s+\Z!!g;

# Trim trailing horizontal whitespace.
s!\h+$!!gm;

# Split the text records into an array.
my @array = split(/\n{2}/, $_);

# Concatenate the individual text records into a single line.
s!\n! -- !gm for @array;

# Set the Output Separator character.
$, = "\n";

print @array;
print "\n\nCounts:\n\n";

# Remove all text from records other than the name.
s!\h*--.+$!!gm for @array;

# Acquire counts for each record name (key) and print:
my %counts = ();

for (@array) {
   $counts{$_}++;
}

foreach my $keys (keys %counts) {
   print "$keys = $counts{$keys}\n";
}


-- 
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/676F98B6-3F7D-4853-917F-2BC198B96220%40gmail.com.

Reply via email to