Thank you! This is helpful, and the result better than mine was. However, when I run the text filter, not all occurrences of the first element get replaced when necessary:
[image: tab3.png] Here a tab should also replace A1 in line 5, A2 in line 12, and A3 in line 18. Thanks samar On Saturday, March 20, 2021 at 4:41:36 PM UTC+1 John R M. Delacour wrote: > > 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/71112be2-d039-4014-9daf-38608374fb49n%40googlegroups.com.
