This sounds amazingly powerful and flexible. Thanks a lot. I will try it asap. The only problem is that I will need to learn Perl if I want to be able to write such scripts…
Le samedi 6 octobre 2012 01:25:58 UTC+2, eremita a écrit : > > > On 5 Oct 2012, at 16:18, jmichel <[email protected] <javascript:>> > wrote: > > > I have a file consisting of groups of lines (unknown number of lines in > each group). > > Each line begins by a 6 digit number, followed by an unknown sequence of > words and numbers. > > Consecutive lines starting with the same number form a group. > > My problem is to combine lines from each group into a single line, > keeping only the first occurrence of the distinctive number. > > I have been able to "find" groups using the pattern > > (\d{6})(.+)(?:\r\1(.+))+ > > However, this does not appear to store the expressions matching the > inner parentheses into separate variables. > > Is there a way to achieve the desired replacement using grep? > > Using regular expressions yes, but you need a routine. If you put a file > containing > this Perl Script in ~/LibraryApplication Support/BBEdit/Text Filters, it > will do what > you want. Open the Text Filters palette from the Window menu and you will > see the > filter. Double-click it or click on Run or, if its a frequent task, > assign a shortcut to the > script. > > Save this as ???.pl > > #!/usr/bin/perl > my %hash; > my $six_digits = "[0-9]{6}"; > my $remaining_text = ".*"; > my $delimiter = ""; # or ", " for example > while (<>) { > if ( /^($six_digits)($remaining_text)/ ) { > $hash{$1} .= $2 # append the text after the 6 digits > } > } > for (sort {$a<=>$b} keys %hash) { > print "$_$delimiter$hash{$_}\n" > } > > #JD > > > -- -- You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at <http://groups.google.com/group/bbedit?hl=en> If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group. Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>
