Hello,

Perl is a very good language for this
problem as il allows to write things
very simply.

----------------------------------
#!/usr/bin/perl
my $line = 0;
@ARGV = ("/Users/michel/Desktop/and.txt");
#write here the path to your file
$count = 0;
$word = " ";
while (<>) {
               foreach $word (m/(\band\b)/ig) {
#\b here means here word boundaries
#if you don't know what it is see
#grep reference inside your BBEdit application
#I have done here a case insensitive search
#if you want a case sensitive search remove the
#"i".
                   $count ++;
               }
           }
print "The number of occurences is: ", $count,"\n";
#-----END-------
--
Michael Havlicek
On Mar 19, 2007, at 2:55 PM, Kjetil Rå Hauge wrote:

Elie Boulos wrote:
I need to find the number of instances of an arbitrary string
in a single text file, is this possible through AppleScript?
Search matches doesn't have such a number. For example, I need to find out the count of the word 'and' in
a text containing "He bought a hammer and a nail and a tape and
a screw driver" (that's 3 and's)
Possible?

I'd use the replace command and replace "and" by "and". The result will be the number of occurrences replaced:

set theWord to "and"
set a to replace theWord using theWord searching in contents of document 1 options {starting at top:true}
        display dialog a

But I am sure there are other ways to skin this cat. Using this method you either have to pay attention to your case sensitivity option so that the text is not changed into something you do not want, or take care not to save the document after the search.


-- ---
Kjetil Rå Hauge, U. of Oslo, PO Box 1003 Blindern, N-0315 Oslo, Norway
Tel. +47/22856710, fax +47/22854140

-- ----------------------------------------------------------------------- -
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>



--
------------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to:  <[EMAIL PROTECTED]>

Reply via email to