On May 25, 2012, at 08:30, JT wrote:
> Does anyone know if there is a way to process lines not containing a grep
> pattern?
______________________________________________________________________
Hey JT,
Any of these could be used with a static regex pattern or with a display dialog
to allow you to input a pattern on the fly.
Note that these are very plain-jane; I'm not doing error-checking for unmatched
patterns, etc.
--
Best Regards,
Chris
# Probably the simplest for automation purposes.
------------------------------------------------------------------------------------------------
tell application "BBEdit"
tell text of front text document
set its contents to copied lines of (process lines containing
matching string "essential|power" with matching with grep)
end tell
end tell
------------------------------------------------------------------------------------------------
# Pretty ugly shell routing using egrep -v
# Ugly because it leaves gaps where lines are deleted.
------------------------------------------------------------------------------------------------
tell application "BBEdit"
tell text of front text document
set _text to quoted form of (get its contents)
set its contents to do shell script "echo " & _text & " | tr
'\\r' '\\n' | egrep -iv \"believe|entirely\""
end tell
end tell
------------------------------------------------------------------------------------------------
# My usual preference using the Satimage.osax, although the process-lines
routing is very straightforward.
# I like using it because it's a very familiar tool, and I have very fine
control over what it does.
------------------------------------------------------------------------------------------------
on fnd(findStr, srcData, caseSensitive, allOccurrences, stringResult)
try
set findResult to find text findStr in srcData ¬
case sensitive caseSensitive ¬
all occurrences allOccurrences ¬
string result stringResult ¬
with regexp
return join findResult using return
on error
return false
end try
end fnd
------------------------------------------------------------------------------------------------
tell application "BBEdit"
tell text of front text document
set its contents to my fnd("^.*(essential|power).*", (get its
contents), false, true, true)
select insertion point before character 1
end tell
end tell
------------------------------------------------------------------------------------------------
# Also using the Satimage.osax but without the handler.
------------------------------------------------------------------------------------------------
tell application "BBEdit"
tell text of front text document
set its contents to join (find text "^.*(essential|power).*" in
(get its contents) ¬
regexp true ¬
case sensitive false ¬
all occurrences true ¬
with string result) using return
select insertion point before character 1
end tell
end tell
------------------------------------------------------------------------------------------------
--
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>