On Sep 03, 2012, at 01:42, AB <[email protected]> wrote:
> Can anyone help with a script or text filter to add a number after a string
> in a file
______________________________________________________________________
Hey AB,
Kendall's Perl script is far superior for speed with nearly instant replacement
of sample text with 450 replacements.
Nevertheless it can be done pretty easily with Applescript:
-------------------------------------------------------------------------
set regexStr to "\\b(the)\\b"
set _cntr to 0
tell application "BBEdit"
tell front text window's text
select insertion point before character 1
repeat
set fndRec to find regexStr options {search mode:grep,
case sensitive:false}
if (found of fndRec) = true then
set _cntr to _cntr + 1
tell (a reference to found object of fndRec)
set its text to (get its text as text)
& _cntr
end tell
else
exit repeat
end if
end repeat
select insertion point after character -1
end tell
end tell
-------------------------------------------------------------------------
This script however takes about 4 seconds to complete on the same example text
when run from BBEdit's script menu.
--
Best Regards,
Chris
--
--
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>