Process line not containing

79 views
Skip to first unread message

JT

unread,
May 25, 2012, 9:30:06 AM5/25/12
to BBEdit Talk
Hi All,

Does anyone know if there is a way to process lines not containing a
grep pattern? At the moment I am using the process lines containing
and copying to clipboard, pasting over current document and saving. I
would much prefer to be able to delete everything in the document that
doesn't match as it would help me with automation.

Cheers,

JT

Fritz Anderson

unread,
May 25, 2012, 10:17:00 AM5/25/12
to bbe...@googlegroups.com
I'd think all you need do is to check the "Delete matched lines" and uncheck "Copy to new document" in the Process Lines Containing… dialog.

Do I misunderstand you?

— F

Christopher Stone

unread,
May 26, 2012, 3:03:24 AM5/26/12
to bbe...@googlegroups.com
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
------------------------------------------------------------------------------------------------

Reply all
Reply to author
Forward
0 new messages