• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Count word's occurences
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Count word's occurences


  • Subject: Count word's occurences
  • From: Guido Tangorra <email@hidden>
  • Date: Mon, 08 Sep 2014 09:53:03 +0200

I'm generating a text document in TextWrangler, a sort of name list, dinamically with AS. 
This could be an example of the file I'm generating:
-----------
apple
grape
banana
ananas
orange
apple
apple
orange
--------------

I need to print the occurrences of every word in this document too.
So I would something like:

-----------
apple 1
grape 1
banana 1
ananas 1
orange 1
apple 2
apple 3
orange 2
--------------

I'm using this handler:

#Word Counter

on findLr(the_string, charTF)

set AppleScript's text item delimiters to charTF --use of the searched string to separate bits

set the_list to text items of the_string --put those bits in a list

set charNbr to ((count of the_list) - 1) --count those bits, minus 1

set AppleScript's text item delimiters to ""

return charNbr

end findLr


This is working fine, but I'm wondering if there's a better or a more efficient way to do the same. Maybe with grep or ASObjC Runner or with a built-in command in TextWrangler.

The file has thousands of lines and it's generated dynamically so the performances are critical.



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Count word's occurences
      • From: Thomas Fischer <email@hidden>
    • Re: Count word's occurences
      • From: Christopher Stone <email@hidden>
    • RE: Count word's occurences
      • From: "Lanphier, Daniel A." <email@hidden>
    • RE: Count word's occurences
      • From: "Lanphier, Daniel A." <email@hidden>
    • Re: Count word's occurences
      • From: Shane Stanley <email@hidden>
  • Prev by Date: Re: Date Disaster
  • Next by Date: Re: Count word's occurences
  • Previous by thread: Re: Date Disaster
  • Next by thread: Re: Count word's occurences
  • Index(es):
    • Date
    • Thread