On 20 Mar 2021, at 11:30, samar <[email protected]> wrote:

> I'm looking for something which I assume is pretty easy to accomplish with 
> GREP but I fail to see how.
> 
> I have a large text file with entries sorted in this way:
> 
> ...That is, the first element is replaced by a tab character *if* the first 
> element is a repetition of the first element of the previous line(s). The 
> sort order remains unchanged.

Create a text filter "~/Library/Application Support/BBEdit/Text 
Filters/SAMAR.pl" and run it from the Text Filters palette (opened from Window 
menu).  The script will affect the whole file, or just the selection if one is 
made:


#! /usr/bin/perl
my $a;
while (<>) {
        my ($col1, $col2) = split "\t", $_;
        if ($col1 eq $a) {
                print "\t$col2"
        } else {
                print "$col1\t$col2";
                $a = $col1;
        }
}

-- 
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/4EE3BAFE-E482-4CDD-A428-EAF083608F4A%40gmail.com.

Reply via email to