At 8:41 PM -0600 11/1/10, Doug McNutt sent email regarding Re:
Replace on Different Line Than Find?:
I confess that I don't know how BBEdit currently handles filters
that run in perl. ...
If you use an ordinary Terminal session with the perl code named as
you indicate you would first make sure your working directory is set
with chdir and then enter:
perl -w TitleYear.pl < Phantom.txt
# - and later. . .
perl -w TitleYear.pl < Kong.txt
I use a number of Perl scripts that are embedded within AppleScrip
wrappers so I can drag and drop files onto them for processing. So
far though, they've all been simple find/replace. For example:
#!/usr/bin/perl -i
use strict;
use warnings;
local $/;
while ($_ = <>) {
#if ($string =~ m/seriesID/)
{
s/seriesID/seriesId/m;
s/\ =\ /\ :\ /mg;
}
print;
}
The above script is in the app bundle that calls the script just once
with all the dropped files concatenated:
-- We call the perl script one time with the paths of all dropped files
-- concatenated to the command line.
on open dropped_items
set perlScript to quoted form of (POSIX path of (path to me) &
"Contents/Resources/metadata.pl")
set commandLine to perlScript
repeat with this_item in dropped_items
-- we don't want to process .mpg files dropped inadvertently
if (POSIX path of this_item) ends with ".txt" then
-- add this dropped text file to the command line
set commandLine to commandLine & " " & quoted form of POSIX
path of this_item
end if
end repeat
do shell script commandLine
end open
I have some other AppleScripts that loop through the dropped files,
calling the internal Perl script once for each dropped file.
The < redirection operator tells the shell to use the file following
it to be given to the perl filter as standard input.
AH! I wondered what that was. It's not used in any of my Drag-n-Drop scripts.
Usually, once I can figure out the GREP, I can cobble together
another AS droplet based on one of my current, functional ones. My
Perl knowledge is of the "Monkey see, monkey do" variety so I clone
one of my scripts that works and modify as needed.
The RegX had me stumped for a while because it seemed like two
separate searches, one to find the four digits, another to find the
line to which the digits would be appended.
Then I realized that the digits always come before the target line,
so it can all be done with one search / replace.
Thanks, I'm sure your examples will help.
--
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>