On 28/4/13 at 20:13, [email protected] (LuKreme) wrote:

I have a file that looks like this:

123456 "/path/to/file name/with spaces"

with several thousand lines.

I want to run a text-factory that gets the number, runs it
through a bit of python code, and replaces it with the result
without touching the rest of the line. So I would end up with
something like

8578810 "/path/to/file name/with spaces"...

Use a Text Filter, not a factory. I don't know Python, but the process will be very similar to the Perl routine below. Here I have used a subroutine for the math stuff in case it's lengthy:

#!/usr/bin/perl
use strict;
while (<>) {  # read the text line by line
  my $number;
  if (/^\d+/) { # if a string of digits begins the line
    my $changed_number = ChangeNumber($&); # process the found item
    s/$number/$changed_number/; # substitute the calculated replacement
  }
  print ; # replace the line with the modified line
}
sub ChangeNumber {
  return $_[0] * 2; # multiply the first parameter by 2
}

#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>

--- 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].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to