On 21 Mar 2021, at 19:37, Christopher Stone wrote:

On 03/21/2021, at 03:39, samar <[email protected] <mailto:[email protected]>> wrote:

The reason you cannot reproduce the error with your file may be that the second column is limited to three different texts (B1, B2, and B3) whereas in mine there are more (up to B7 here, but the script should also work with more than seven):



Hey Samar,

Nyet. The logic of JD's script is quite clear if you know how to read Perl, and that shouldn't happen.

Hmm. When I first read Samar’s post - the one with the enclosed screen shots - I thought he wanted it to go from something like this:

A1[tab]B1
[tab]B2 
[tab]B3 
[tab]B4 
[tab]B5
A2[tab]B1
[tab]B2 
[tab]B3
[tab]B4
A3[tab]B1       
[tab]B2 
[tab]B3 
[tab]B4 
[tab]B5 
[tab]B6 

to something like this:

A1[tab]B1
A1[tab]B2       
A1[tab]B3       
A1[tab]B4       
A1[tab]B5
A2[tab]B1
A2[tab]B2       
A2[tab]B3
A2[tab]B4
A3[tab]B1       
A3[tab]B2       
A3[tab]B3       
A3[tab]B4       
A3[tab]B5
A3[tab]B6       

If this is correct, JD’s script could be easily changed to do it.

Note that to get the first $x ($a in JD’s script), you have to parse & print the first line before looping over the rest.

And this assumes that the first line has a value in both columns.


#!/usr/bin/perl
my ($x, $y) = split "\t", <>;
print "$x\t$y";
while (<>) {
        my ($col1, $col2) = split "\t", $_;
        if ($col1 and $col1 ne $x) {
                $x = $col1;
        }
        print "$x\t$col2";
}

But maybe I misunderstood the goal.


HTH,

    - Bruce

_bruce__van_allen__santa_cruz__ca

--
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/5903E9EF-FB0E-4D63-BBD5-35A8B56889A2%40cruzio.com.

Reply via email to