> >How do I go about deleting lines X through Y in TextWrangler? I don't > >want to have to manually select them because there are like 10,000 > >lines.
> Depending on how those lines are delimited, there may be other ways to do > this (e.g. a search with "Extend Selection"), but the basic procedure is:
> * turn on "Show Line Numbers" via the Text Options popup, or Edit -> Text > Options
> * scroll to line X
> * set the insertion point at the start of line X
> * scroll until line Y is in view
> * Shift-click at the beginning of line Y+1 (which will select everything > from line X to that point)
An alternate "cheating" method could also be this (turn 'grep' on):
Search: \A((?:.*\r){50})(?:.*\r){20} Replace: \1
\A matches the very top of the document.
( (?:.*\r){50} ) has a matching group and a non-matching group. The non-matching group contains "everything up to a newline character" which is then repeated 50 times. The outer "matching" group will store all 50 lines that were just captured so we can stick it back into the "\1" replacement.
(?:.*\r){20} is another non-matching group of 20 lines. You plan to delete these lines, so there is no reason to "capture" them (the construct of (?: ... ) means not to "collect" the text in it).
So if you have exactly 200 lines that you want to save at the top of the document, then 10,000 lines after that which you want to remove, simply adjust your {50} and {20} respectively, and you're good to go. :-)
On Nov 04, 2012, at 07:56, Derek Neil <krazyde...@gmail.com> wrote:
> THANK YOU!
> On Friday, 13 March 2009 18:39:14 UTC-3, Patrick Woolsey wrote:
>> Depending on how those lines are delimited, there may be other ways to do this (e.g. a search with "Extend Selection"), but the basic procedure is:
It's easy enough to delete a contiguous range of lines.
This script expects input in the form of '10:20' (no quotes) — where the first number is the start-line and the second number is the end-line of the range.
You can change the default answer to whatever you'd like.
set delRng to text returned of ¬
(display dialog "Enter Range of Lines to Delete:" default answer "1:100" giving up after 60)
set AppleScript's text item delimiters to ":"
set delRng to text items of delRng
if length of delRng = 2 then
set {startRng, endRng} to text items of delRng
tell application "TextWrangler"
tell front text window
delete (lines startRng thru endRng)
end tell
end tell
end if
on error e number n
set e to e & return & return & "Num: " & n
tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
if button returned of dDlg = "Copy" then set the clipboard to e
end try