On Jan 07, 2022, at 15:10, David G Wagner <[email protected]> wrote:
> Here is the data that I am working with.


Hey David,

This is why it's so important to provide real-world data samples – both input 
and output – when asking for help to process text.

Here is a very robust method that lets you use a regular expression to split 
the text records.

The case of the split-string in insensitive and is also standardized in the 
file.

--
Best Regards,
Chris


#!/usr/bin/env perl
# 
-----------------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2022/01/09 13:36
# dMod: 2022/01/09 13:36
# Task: Number Lines Based On A Condition.
# Tags: @ccstone, @Shell, @Script, @Number, @Lines, @Condition, @bbedit-talk, 
@David_Wagner
# 
-----------------------------------------------------------------------------------------

my $cntr    = 1; 
my $recSep  = "#Start#";                # Pseudo Input-Record-Separator
local $/    = 0777;                     # Set Actual IRS to Slurp-Mode

$_ = <>;                                # Slurp up all the text
$_ =~ s!^$recSep!$recSep!gim;           # Standardize #Start# case
my @array = split /^$recSep\h*/im, $_;  # Split the text into an array

for my $element (@array) {              # Loop through the array and replace
    $element =~ s!^1(?=\h)!$cntr++!em;  # the first instance of “^1” with $cntr
}

$, = $recSep;                           # Set output-record-separator
print @array;

# 
-----------------------------------------------------------------------------------------

-- 
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/12F87FED-0C62-4C0D-8D95-4839EBB66A34%40gmail.com.

Reply via email to