At 11:00 -0700 10/08/2011, rowen wrote:
I'd want to write a script that reports the sum and mean of a column
of numbers that are selected using column selection.
I have a Python text filter that does this now with normally selected
text (working on the first number found on each line), but it writes
the information after the selected text (by echoing the input and then
writing the new info). That technique won't work with a column
selection; there's no obvious place to safely write the results.
I would prefer to open a new window and write the results there. Is
there some easy way to do this? From a Python script?
I don't know Python but here's how you could do it in Perl
You have to copy your selection onto the clipboard because the text
filters read whole lines. Overwrite the selection, then create a
file for your results. Perform your calculations on $clipboard,
write the results to the new file and open this in BBEdit.
This script multiplies every number in your selected column by 2 and
displays the results in the doc $tempfile:
#! /usr/bin/perl
use strict;
my $clipboard = `pbpaste`;
my $tempfile = "/tmp/temp.txt";
while (<>) {print}
open FH, ">", $tempfile or die $!;
for (split /[\n\r]/, $clipboard){
$_ *= 2;
print FH "$_\n";
}
`open -a bbedit $tempfile`;
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>