Re: scripting bbedit
Re: scripting bbedit
- Subject: Re: scripting bbedit
- From: Ricardo Montiel <email@hidden>
- Date: Wed, 27 Jun 2001 13:40:08 -0300
on 26 Jun 2001 16:30, "Arthur Cormack" at <email@hidden> wrote:
>
What is the smartest way to search a big text file an occurance of
>
specific word and return the number of the line that that word occurs
>
on?
>
Is BBEdit the tool to use? Does anyone know if there is a command in
>
BBEdit's scripting commands that would return this line number?
Hi Arthur,
I am not sure if this could be the smartest way (you did not gave us more
details: what are you going to do with the matched lines?), but I definitely
will use a multi file search. As Multi file searches can not be performed on
single files that aren't projects, so you would have to create a folder and
put in it your file (if you are going to run the script on a daily-basis,
I'd recommend to script the former process - not shown in my example).
Here is an example of how to do it...
set mystring to "your specific word"
set mydir to "xDisk:xFolder:"
set templineList to {}
tell application "BBEdit 5.1"
set myfind to find mystring starting at mydir with multi file
repeat with mymatch in myfind
copy (line of mymatch) & return to templineList's end
end repeat
make new document with properties {contents:templineList as text}
end tell
You will see in a new window the matching lines or a blank page if the
search result have no hits.
One caveat: do not change or mix the soft wrap command boolean value, or the
line numbers may be pointing to a wrong place in your document. I have been
told that BBEdit 6.x addressed this drawback, so may it will be a better
approach to adapt and to run the script on the newer version.
I hope this helps.
Saludos (Regards),
Ricardo Montiel
Buenos Aires - Argentina
PS: Please cc me, on digest.